Hello,
I am having a difficult time referencing the instance id of an EC2 resource 
that I have just created. After I create it, I would immediately like to 
terminate it. My code is below:

Thank you,
Bill

---
- name: Example of provisioning servers
  hosts: 127.0.0.1

  connection: local
  tasks:
   - name: set_fact1
     set_fact: foo = 1

   - name: Create security group
     local_action:
       module: ec2_group
       name: ep2
       description: Access to the Episode2 servers
       region: us-east-1
       rules:
         - proto: tcp
           from_port: 22
           to_port: 22
           cidr_ip: 0.0.0.0/0

   - name: Launch instances
     local_action:
       module: ec2
       instance_tags:
        Name: server1
        Env: myenv
       region: us-east-1
       keypair: ansiblekeypair
       group: ep2
       instance_type: m1.small
       image: ami-1aae3a0c
       count: 1
       wait: yes
     register: ec2

   - name: Terminate instances that were previously launched
     ec2:
       state: absent
       region: us-east-1
       instance_ids: "{{ ec2.instance_id[0] }}"
     with_items: ec2

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/7b53bda1-92de-4efa-afdb-e92d5dfbf6a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to