Ansible copy or delete multiple files in parallel

21 views
Skip to first unread message

anushake...@gmail.com

unread,
Nov 23, 2018, 1:15:36 PM11/23/18
to Ansible Project
Hi Team,

Can we copy or delete files in parallel instead of sequence for different locations when using with_items. 

---
- hosts: all
  tasks:
    - name: Copying files
      copy: src={{ item.src }} dest={{ item.dest }}
      with_items:
        - { src: '/tmp/abc.war', dest: '/tmp/abc' }
        - { src: '/tmp/def.war', dest: '/tmp/def' }
        - { src: '/tmp/xyz.war', dest: '/tmp/xyz' }
     

Kai Stian Olstad

unread,
Nov 23, 2018, 1:48:56 PM11/23/18
to ansible...@googlegroups.com
On Friday, 23 November 2018 19:15:35 CET anushake...@gmail.com wrote:
> Can we copy or delete files in parallel instead of sequence for different
> locations when using with_items.

Check out async


--
Kai Stian Olstad


anushake...@gmail.com

unread,
Nov 26, 2018, 11:25:02 AM11/26/18
to Ansible Project
Hi Olstad,

I tried with async but I am getting the below error. Could you please help.

Playbook.yml

---
- hosts: all
  tasks:
    - name: Copying files
      copy: src={{ item.src }} dest={{ item.dest }}
      with_items:
        - { src: '/tmp/abc.war', dest: '/tmp/abc' }
        - { src: '/tmp/def.war', dest: '/tmp/def' }
        - { src: '/tmp/xyz.war', dest: '/tmp/xyz' }
      async: 60
      poll: 0

Error:

failed: (item={u'dest': u'/tmp/hr', u'src': u'/tmp/abc/abc.war'}) => {"item": {"dest": "/tmp/abc", "src": "/tmp/abc/abc.war"}, "msg": "async is not supported for this task."}

Kai Stian Olstad

unread,
Nov 27, 2018, 10:59:43 AM11/27/18
to ansible...@googlegroups.com
On Monday, 26 November 2018 17:25:02 CET anushake...@gmail.com wrote:
> I tried with async but I am getting the below error. Could you please help.
>
> Playbook.yml
>
> ---
> - hosts: all
> tasks:
> - name: Copying files
> copy: src={{ item.src }} dest={{ item.dest }}
> with_items:
> - { src: '/tmp/abc.war', dest: '/tmp/abc' }
> - { src: '/tmp/def.war', dest: '/tmp/def' }
> - { src: '/tmp/xyz.war', dest: '/tmp/xyz' }
> async: 60
> poll: 0
>
> Error:
>
> failed: (item={u'dest': u'/tmp/hr', u'src': u'/tmp/abc/abc.war'}) =>
> {"item": {"dest": "/tmp/abc", "src": "/tmp/abc/abc.war"}, "msg": "async is
> not supported for this task."}

It seams that the copy module doesn't support async so you're out of luck.
If you have passwordless login to you host, you could use command module with async.


--
Kai Stian Olstad


Reply all
Reply to author
Forward
0 new messages