OK that makes total sense. Follow up question, what is the syntax in ansible to iterate over every entry in the array.
So for individual results you do ec2.results[0].instance_ids. What do you do for all results or to loop over this to get every instance id from multiple entries. like ec2.results[i].instance_ids or something? *Christopher Stobie* *Lead DevOps Engineer* *ClearCapital, Inc.* (469) 682 2933 [email protected] On Tue, Sep 27, 2016 at 11:15 PM, Kai Stian Olstad < [email protected]> wrote: > On 28.09.2016 03:07, Chris Stobie wrote: > > <snip> > > - name: Create EC2 instance for zone A >> ec2: >> key_name: "{{ keypair }}" >> group: "{{ security_groups }}" >> image: "{{ ami }}" >> instance_type: "{{ instance_type }}" >> wait: true >> region: "{{ ec2_region }}" >> vpc_subnet_id: "{{ subneta }}" >> assign_public_ip: "{{ public_choice }}" >> zone: "{{ zonea }}" >> count: 1 >> instance_tags: >> Name: "db{{ item }}a.{{ env }}" >> envtype: "{{ envtype }}" >> register: ec2 >> with_sequence: "start=1 end={{ num }}" >> > > Remember that all the with_ is a loop, and the register is a little > different as described here > https://docs.ansible.com/ansible/playbooks_loops.html#using- > register-with-a-loop > > The result is stored in a list ec2.results > > <snip> > > ok: [localhost] => { >> "msg": { >> "changed": true, >> "msg": "All items completed", >> "results": [ >> > > Here you can see the results list. > > > <snip> > > >> >> So I can see that the variable that should exist does in the output of the >> full ec2 variable. But when trying to use the key specific variable of >> ec2.instance_ids it fails... >> > > The correct entry would be ec2.results[0].instance_ids for the first > iteration of the loop and for the second iteration > ec2.results[1].instance_ids and so on. > > -- > Kai Stian Olstad > > -- > 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/ms > gid/ansible-project/869c4cc59eac8af3ba98fd957eedafea%40olstad.com. > > For more options, visit https://groups.google.com/d/optout. > -- 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/CAHFHBDpXrgpB2SE%2B%2B_f6TUFfEMjFe_noVx8YwoNgHYMe%3D4%3D5qQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
