---
- hosts: all
become: yes
#connection: local
tasks:
- name: Get Instance info
register: ec2_facts
- name: setting fact for Security group
set_fact:
SERCURITYGROUP : "{{ item.group_name }}"
with_items: "{{ ec2_facts.instances[0].network_interfaces[0].groups }}"
- hosts: localhost
gather_facts: False
vars:
keypair: ansible
instance_type: m1.small
image: "{{ ami_id }}"
region: us-east-1
subnet: "{{ SUBNETID }}"
tasks:
- name: Launch instance
ec2:
key_name: "{{ keypair }}"
group: "{{ SERCURITYGROUP }}"
instance_type: "{{ instance_type }}"
image: "{{ image }}"
wait: true
region: "{{ region }}"
vpc_subnet_id: "{{ subnet}}"
assign_public_ip: yes
register: ec2