Re: [ansible-project] ansible 2 lists in playbook vars file
On 09. juli 2017 00:09, Anfield wrote: Hi, Thanks for the reponse. This works but I dont quite understand it... So copylist is now basically a list with two listed values - src - src How does it pick up dest when its not really designated as a list item with a dash (-)? I wouldve expected -dest to be listed aswell twice The dash indicate start of a list item. And item contains a dictionary, this has two element src and dest. You can write a list of dictionary in two ways copylist: - src: /home/ansible/tom/tom.txt dest: /home/ansible/tom1 - src: /home/ansible/fred/fred.txt dest: /home/ansible/fred1 or copylist: - {'src':'/home/ansible/tom/tom.txt', 'dest':'/home/ansible/tom1'} - {'src':'/home/ansible/fred/fred.txt', 'dest':'/home/ansible/fred1'} Which syntax used, come down to personal preferences. -- 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 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/067c02d0-11f9-bbab-148a-43935607c746%40olstad.com. For more options, visit https://groups.google.com/d/optout.
Re: [ansible-project] ansible 2 lists in playbook vars file
On Sat, Jul 8, 2017 at 6:09 PM, Anfield wrote: > Hi, > > Thanks for the reponse. This works but I dont quite understand it... > > So copylist is now basically a list with two listed values >- src >- src > > How does it pick up dest when its not really designated as a list item with > a dash (-)? > I wouldve expected -dest to be listed aswell twice > Does this give you ideas? # In vars file/entry normal_users: - moe : { uid : "1205", groups : "{{web_groups}},wheel" } - larry : { uid : "1203", groups : "{{web_groups}}" } - curly : { uid : "1207", groups : "{{web_groups}}" } # In task file - name: List all Normal Users debug: msg="Users {{ normal_users }} " - name: List Normal Users one at a time debug: msg="Users {{ item }} " with_items: "{{ normal_users }} " > -- > 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/6f9dc917-80a1-42ec-bb7c-65659fac9d43%40googlegroups.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 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/CAHEKYV4LsxrSBpx2zX0hxXVe6qAq1PxnDXcRyA3X2%3Dnae6Kerg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: [ansible-project] ansible 2 lists in playbook vars file
Hi, Thanks for the reponse. This works but I dont quite understand it... So copylist is now basically a list with two listed values - src - src How does it pick up dest when its not really designated as a list item with a dash (-)? I wouldve expected -dest to be listed aswell twice -- 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/6f9dc917-80a1-42ec-bb7c-65659fac9d43%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [ansible-project] ansible 2 lists in playbook vars file
On 08. juli 2017 23:52, Anfield wrote: Trying to get a playbook working with yml file containing 2 lists and passing that into the main file to loop over. Can someone help with letting me know what I'm doing wrong? Thanks copylist.yml --- copylist: src: - /home/ansible/tom/tom.txt - /home/ansible/fred/fred.txt dest: - /home/ansible/tom1 - /home/ansible/fred1 This is not a list its a dictionary. Playbook - copy.yml --- - hosts: localhost become: yes vars: users: - tom - fred vars_files: - copylist.yml tasks: - name: Create users from vars user: name: "{{item}}" state: present with_items: "{{users}}" - name: Copy files into target directories copy: src: "{{item.src}}" dest: "{{item.dest}}" with_items: "{{copylist}}" Since copylist is not a list but a dictionary this fails. You need to write copylist as list you like this and you task will work. copylist: - src: /home/ansible/tom/tom.txt dest: /home/ansible/tom1 - src: /home/ansible/fred/fred.txt dest: /home/ansible/fred1 -- 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 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/e0f2f6a6-daff-7488-74c5-3fd823e5db38%40olstad.com. For more options, visit https://groups.google.com/d/optout.