Hmm. That seems rather complex. Do you happen to know what the prescribed 
method of doing this is? Does Ansible recommend using add_hosts <the 
http://docs.ansible.com/ansible/add_host_module.html> module?  

On Tuesday, June 20, 2017 at 8:21:59 PM UTC-5, Michael Bushey wrote:
>
> I don't think this works in Ansible. The ec2 functionality seems very 
> marginal and defective. I split the playbooks into two parts. The first 
> spins up the instance. Then I go to the aws console to assign the correct 
> IAM role to the instance as I can't figure out how to do this in Ansible. 
> Then I run 
>
> ssh {IP or name} "test -e /usr/bin/python || (apt -qqy update && apt 
> install -qqy python-minimal)" 
>
> to install python 2.x so Ansible can run commands on the machine. Then I 
> can run the second playbook to configure the server.
>
>
>
> On Tuesday, June 20, 2017 at 2:18:28 PM UTC-7, Bill L. wrote:
>>
>> 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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/63276359-6e58-431e-b29b-da54edbe7734%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to