do you want to copy multiple target like this?
# 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
On Monday, October 29, 2018 at 10:25:37 PM UTC+5:30, [email protected]
wrote:
>
> Hi,
>
> I am trying to copy multiple files to different locations using
> with_items. Could someone please help me with this
>
> *vars: main.yml*
>
> wars:
> file1.war
> file2.war
> file3.war
> file4.war
>
> dest_path:
> /tmp/{wars}
>
>
> *tasks- main.yml*
> ---
> - hosts: all
> name: copy file
> copy: src={{ item.src }} dest={{ item.dest }}
> with_items:
> - { src: '{{ wars }}', dest: '{{ dest_path }}' }
>
> My idea is file1.war should go to /tmp/file1 folder etc
>
--
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/db3a58e4-a982-47a0-8a33-5f9291ff6dcd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.