- name: Launch instance
ec2:
key_name: ansible
group: "{{ group }}"
instance_type: m1.small
image: "{{ image }}"
wait: true
region: "{{ region }}"
vpc_subnet_id: "{{ subnet}}"
assign_public_ip: yes
register: ec2
- name: Add new instance to host group
add_host:
hostname: "{{ item.public_ip }}"
groupname: test
loop: "{{ ec2.instances }}"
- name: Waiting for SSH to come up
delegate_to: "{{ item.public_ip }}"
wait_for_connection:
delay: 60
timeout: 320
loop: "{{ ec2.instances }}"
- hosts: test. ##blank in the inventory file, but new instance added to it so i can connect to the new instance with password and key
become: True
gather_facts: True
tasks:
- name: Testing out the servers
shell: ". /etc/profile; echo $DEV_ENV"
args:
executable: /bin/bash
register: ENTRY
- name: Output for test server
debug: msg="{{ ENTRY.stdout }}"
- name: getting instance id again
register: instanceterminate
- name: Terminate instances that were previously launched
ec2:
state: 'absent'
instance_ids: "{{ instanceterminate.stdout }}"
region: us-east-1
# when: ENTRY.rc == 0 or ENTRY.rc >= 2