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.