>
>
>> <https://lh3.googleusercontent.com/-cvX4IudbEQo/WQCllh2EK6I/AAAAAAAAAH0/m-RoG7m1Un4ut28Ffw5xlYjCW-sZOyYcgCLcB/s1600/Screenshot%2B%25281104%2529.png>
>>   tasks:
>>
>>   - name: Launch EC2 instance
>>     ec2:
>>        key_name: "{{keypair}}"
>>        group: default
>>        count: "{{count}}"
>>        instance_type: "{{instance_type}}"
>>        instance_tags: '{"Name": 
>> "{{item.names}}","Type":"{{tag_Type}}","Environment":"{{tag_Environment}}"}'
>>        image: "{{image}}"
>>        wait: true
>>        region: "{{region}}"
>>
>>        aws_access_key: *****
>>        aws_secret_key: *****
>>     register: ec2
>>     with_items:
>>       - names: Ansible-1
>>       - names: Ansible-2
>>
>>
>>   - name: One Add the newly created EC2 instance(s) to the local host 
>> group (located inside the directory)
>>     local_action: lineinfile dest="/etc/hosts" regexp={{ item.public_ip 
>> }} insertafter="[launched]" line="{{ item.public_ip }} 
>> ansible_ssh_private_key_file=~/.ssh/{{ keypair }}.pem"
>>
>>     with_items:  "{{ec2.instances}}"
>>  
>>
>  

>  - name: wait for ssh to come up
>>     wait_for:
>>       host: "{{ ansible_host }}"
>>       port: 22
>>       delay: 60
>>       timeout: 320
>>       state: started
>>
>>     with_items: "{{ec2.instances}}"
>>
>>   - name: Print all ec2 variables
>>     debug: var=ec2
>>
>>
<https://lh3.googleusercontent.com/-dbp1hcpEmz0/WQCmehD9_oI/AAAAAAAAAIA/yGn1basj9D4I0UgOYEvpI4MbezIJUgusgCLcB/s1600/Screenshot%2B%25281104%2529.png>
 

On Wednesday, April 26, 2017 at 6:47:26 PM UTC+5:30, [email protected] 
wrote:
>
> A variable does not disappear after being used in an item loop, so I 
> suspect you aren't referring to the variable correctly in the second task. 
> Please post an example playbook and the full -vvvv output with the error.
>
> On Tuesday, April 25, 2017 at 2:55:27 PM UTC-4, balubhai555 wrote:
>>
>> Hello team,
>>
>> I want to 
>>
>>    1. Create AWS ec2 instance using one "*with_items: ec2"*
>>    2. After that I want to insert the IP address of those instances into 
>>    */etc/ansible/hosts*  file. For that I am using *local_action: 
>>    lineinfile . *But after that I want to use again with_items: 
>>    "{{ec2.instances}}"
>>
>>
>> At that time it shows error, That Item is undefined.
>>
>> Are we use those with_items twice in a playbook. Any example please 
>> suggest me. 
>>
>> Thank you in advance. 
>>
>>

-- 
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/d38a0dc3-fac7-4c63-92aa-eed8196dc8ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to