How to copy directory recursively using pattern to remote machine?

29 views
Skip to first unread message

Ankit

unread,
Jun 1, 2020, 7:49:09 AM6/1/20
to Ansible Project
Hello All,

I have got the following playbooks where i am trying to copy directories and all its contents recursively which is present in project repo. For identifying the correct directory, i am using a variable which holds the pattern value. For some reason, the task is skipped and the full verbose too doesn't give me enough information about where it is failing. Can someone please suggest.

---
- hosts: all
  gather_facts
: no
  become
: yes
  vars
:
    appid
: '1554'
  tasks
:
   
- name: Copy each file over that matches the given pattern
      copy
:
        src
: "{{ item }}"
        dest
: "/tmp"
      with_fileglob
:
       
- /home/DS/ram/playbooks/app_dir_{{ appid }}*


Output -vvvv :
PLAY [all] **************************************************************************************************************************************************
META
: ran handlers


TASK
[Copy each file over that matches the given pattern] ***************************************************************************************************
task path
: /home/DS/ram/playbooks/copyDirLinux.yml:8
META
: ran handlers
META
: ran handlers


PLAY RECAP
**************************************************************************************************************************************************
host1              : ok=0    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0
host2              : ok=0    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0


and the following directory IS present: /home/DS/ram/playbooks/app_dir_1554_cca


- Regards

Stefan Hornburg (Racke)

unread,
Jun 1, 2020, 8:00:53 AM6/1/20
to ansible...@googlegroups.com
On 6/1/20 1:49 PM, Ankit wrote:
> Hello All,
>
> I have got the following playbooks where i am trying to copy directories and all its contents recursively which is
> present in project repo. For identifying the correct directory, i am using a variable which holds the pattern value. For
> some reason, the task is skipped and the full verbose too doesn't give me enough information about where it is failing.
> Can someone please suggest.
>
> |
> ---
> -hosts:all
>   gather_facts:no
>   become:yes
>   vars:
>     appid:'1554'
>   tasks:
>     -name:Copyeach file over that matches the given pattern
>       copy:
>         src:"{{ item }}"
>         dest:"/tmp"
>       with_fileglob:
>         -/home/DS/ram/playbooks/app_dir_{{appid }}*
>

I think you need to wrap the argument into double_quotes like that:

with_fileglob:
- "/home/DS/ram/playbooks/app_dir_{{appid }}*"

Otherwise it wouldn't interpolate the appid variable.

Regards
Racke

> |
>
> *_Output -vvvv :_*
> |
> PLAY
> [all]**************************************************************************************************************************************************
> META:ran handlers
>
>
> TASK [Copyeach file over that matches the given
> pattern]***************************************************************************************************
> task path:/home/DS/ram/playbooks/copyDirLinux.yml:8
> META:ran handlers
> META:ran handlers
>
>
> PLAY RECAP
> **************************************************************************************************************************************************
> host1             :ok=0   changed=0   unreachable=0   failed=0   skipped=1   rescued=0   ignored=0
> host2             :ok=0   changed=0   unreachable=0   failed=0   skipped=1   rescued=0   ignored=0
>
>
> andthe following directory IS present:/home/DS/ram/playbooks/app_dir_1554_cca
> |
>
>
> - Regards
>
> --
> 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 <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/725e44d4-6342-404f-9cc6-68c3fa4f9f30%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/725e44d4-6342-404f-9cc6-68c3fa4f9f30%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Ankit Vashistha

unread,
Jun 1, 2020, 8:49:21 AM6/1/20
to Ansible Project
Hi Stefan,

Thanks for your comment, i am getting the same issue even after putting that in double quotes.

Regards,
Ankit


To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fdb94a35-6c71-c11a-982f-bab62a56f5e4%40linuxia.de.

Brian Coca

unread,
Jun 1, 2020, 11:39:32 AM6/1/20
to Ansible Project
you are not passing a 'glob' to fileglob, in any case the problem is
that it is returning an empty list, examine it in a debug statement
until you get the output you expect.




--
----------
Brian Coca

Reply all
Reply to author
Forward
0 new messages