# cat site.yml
---
- hosts: all
vars:
file_list:
- file1.txt
- file2.txt
- file3.txt
- file4.txt
tasks:
- name: Copy file to target node
copy:
src: "/tmp/myfiles/{{ item }}"
dest: "/tmp/target/{{ item }}"
with_items: "{{ file_list }}"
# ls -1 /tmp/myfiles/
file1.txt
file2.txt
file3.txt
file4.txt
# ls -1 /tmp/target/
file1.txt
file2.txt
file3.txt
file4.txt
# ansible-playbook -i hosts site.yml -u root
PLAY [all] **********************************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************
ok: [localhost]
TASK [Copy file to target node] *************************************************************************************************************************************
ok: [localhost] => (item=file1.txt)
ok: [localhost] => (item=file2.txt)
ok: [localhost] => (item=file3.txt)
ok: [localhost] => (item=file4.txt)
PLAY RECAP **********************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
# cat site.yml
---
- hosts: all
vars:
file_list:
- { src: '/tmp/myfiles/file1.txt', dst: '/tmp/target1/file1.txt' }
- { src: '/tmp/myfiles/file2.txt', dst: '/tmp/target2/file2.txt' }
- { src: '/tmp/myfiles/file3.txt', dst: '/tmp/target3/file3.txt' }
tasks:
- name: Copy file to target node
copy:
src: "{{ item.src }}"
dest: "{{ item.dst }}"
with_items: "{{ file_list }}"
# ansible-playbook -i hosts site.yml -u root
PLAY [all] **********************************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************
ok: [localhost]
TASK [Copy file to target node] *************************************************************************************************************************************
ok: [localhost] => (item={u'src': u'/tmp/myfiles/file1.txt', u'dst': u'/tmp/target1/file1.txt'})
ok: [localhost] => (item={u'src': u'/tmp/myfiles/file2.txt', u'dst': u'/tmp/target2/file2.txt'})
ok: [localhost] => (item={u'src': u'/tmp/myfiles/file3.txt', u'dst': u'/tmp/target3/file3.txt'})
PLAY RECAP **********************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
Thank you Mohan that worked for me
--
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-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4950ba71-0f0d-4630-8c1c-475fc93f8fc2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
| force bool |
| the default is yes, which will replace the remote file when contents are different than the source. If no, the file will only be transferred if the destination does not exist.aliases: thirsty |
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/01ef6833-b052-43ff-881e-70ad14e427e6%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b6898b5a-9204-4c27-bded-506194a56cfd%40googlegroups.com.
> <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com
> <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/f963a9e3-56c8-4ebb-a3c7-8b7cbe5b812d%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/f963a9e3-56c8-4ebb-a3c7-8b7cbe5b812d%40googlegroups.com?utm_medium=email&utm_source=footer>.
> 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-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9b137ea5-2653-422f-ae02-64bfd4298a6c%40googlegroups.com.