---
- name: "Playbook to spin up new AWS instances"
  hosts: localhost
  connection: local
  gather_facts: False 
  vars:
    - aws_key_name: kp1
    - default_region: us-west-2
    - default_type: t2.micro
    - default_security_group: web
    - default_subnet: subnet-1e6d3958

  tasks:
    - name: "Validate that the required parameters were passed"
      fail: msg="Please pass the required parameters (name, image, role)"
      when: "name is not defined or name == \"\" or image is not defined or image == \"\" or role is not defined or role == \"\""

    - name: "Create the new instance(s)"
      ec2:
        region: "{{ region | default(default_region) }}"
        key_name: "{{ aws_key_name }}"
        instance_type: "{{ instance_type | default(default_type) }}"
        image: "{{ image }}"
        wait: "{{ wait | default('no') }}"
        group: "{{ group | default(default_security_group) }}"
        instance_tags: 
          Name: "{{ name }}"
          role: "{{ role }}"
        user_data: "{{ name }}"
        vpc_subnet_id: "{{ subnet_id | default(default_subnet) }}"
      register: ec2

    - name: "Tag instance(s)"
      ec2_tag:
        region: "{{ region | default(default_region) }}"
        resource: "{{ item.id }}"
        state: present
        tags: "{{ tags }}"
      with_items: ec2.instances
      when: "tags is defined"

    - name: "Create DNS record for somo.int"
      route53:
        command: create
        private_zone: true
        overwrite: yes
        record: "{{ name }}.kiss.int"
        zone: "kiss.int"
        type: A
        ttl: 300
        value: "{{ item.private_ip }}"
      with_items: ec2.instances

Add ansible playbook for creating ec2 instances
Add ansible playbook for creating ec2 instances
