# 'copy' TASK won't copy a file - eventhough reporting 'ok'

**URL:** <https://forum.ansible.com/t/copy-task-wont-copy-a-file-eventhough-reporting-ok/36850>\
**Category:** Ansible Project\
**Created:** [July 14, 2022, 1:41pm UTC](https://forum.ansible.com/t/copy-task-wont-copy-a-file-eventhough-reporting-ok/36850 "2022-07-14T13:41:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [July 14, 2022, 1:41pm UTC](https://forum.ansible.com/t/copy-task-wont-copy-a-file-eventhough-reporting-ok/36850/1 "2022-07-14T13:41:34Z")

</div>

I have a TASK that should copy **~/files/repo\_pgbackrest.conf** to the remote as **/etc/pgbackrest/pgbackrest.conf** (note the differing file name).

however, despite that fact playbook exection returns an ‘ok’ an that TASK, the file is **not pushed** to the remote.

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [July 14, 2022, 1:44pm UTC](https://forum.ansible.com/t/copy-task-wont-copy-a-file-eventhough-reporting-ok/36850/2 "2022-07-14T13:44:47Z")

</div>

> # I have a TASK that should copy \*~/files/repo\_pgbackrest.conf\* to the remote as \*/etc/pgbackrest/pgbackrest.conf\* (note the differing file name). however, despite that fact playbook exection returns an 'ok' an that TASK, the file is \*not pushed\* to the remote.
> 
> # - name: install preps - push config file copy: src: files/repo\_pgbackrest.conf # was: repo\_pgbackrest.conf dest: " {{ item }} " mode: '0640' owner: pgbackrest group: pgbackrest become: true loop: - /etc/pgbackrest/pgbackrest.conf
> 
> Knowing that sometimes things only work after several re-runs I executed this about 5 times with the exact same, unwanted behavior.  
> So ... what am I doing wrong here?

My suspicion would be that you are looking at the wrong target.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [July 14, 2022, 1:49pm UTC](https://forum.ansible.com/t/copy-task-wont-copy-a-file-eventhough-reporting-ok/36850/3 "2022-07-14T13:49:53Z")

</div>

always use -vvv before even asking a question, then also post that info here.

I suspect that the file is there and that ansible is comparing the  
checksums and seeing they are the same and that it does not need to  
make the copy.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [July 14, 2022, 4:00pm UTC](https://forum.ansible.com/t/copy-task-wont-copy-a-file-eventhough-reporting-ok/36850/4 "2022-07-14T16:00:49Z")

</div>

Remove the bogus leading and trailing spaces from `dest:`.

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [July 15, 2022, 9:18am UTC](https://forum.ansible.com/t/copy-task-wont-copy-a-file-eventhough-reporting-ok/36850/5 "2022-07-15T09:18:16Z")

</div>

> Remove the bogus leading and trailing spaces from `dest:`.

spot on! thx. changing

dest: " {{ item }} " to

dest: “{{ item }}”

solves the issue. It’s unexpected though that such a mistake does not produce any kind of error message.

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [July 15, 2022, 9:44am UTC](https://forum.ansible.com/t/copy-task-wont-copy-a-file-eventhough-reporting-ok/36850/6 "2022-07-15T09:44:45Z")

</div>

> > Remove the bogus leading and trailing spaces from `dest:`.
> 
> spot on! thx. changing
> 
> dest: " {{ item }} " to
> 
> dest: “{{ item }}”
> 
> solves the issue. It’s unexpected though that such a mistake does not produce any kind of error message.

Probably because there isn’t an error. You will find that the files are correctly created, likely with a leading and trailing space - as you told ansible to.  
The verbose output will tell - but you didn’t provide that.

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [July 15, 2022, 11:06am UTC](https://forum.ansible.com/t/copy-task-wont-copy-a-file-eventhough-reporting-ok/36850/7 "2022-07-15T11:06:48Z")

</div>

hi,

> > changing
> > 
> > dest: " {{ item }} " to
> > 
> > dest: “{{ item }}”
> > 
> > solves the issue. It’s unexpected though that such a mistake does not produce any kind of error message.
> 
> Probably because there isn’t an error. You will find that the files are correctly created, likely with a leading and trailing space - as you told ansible to.  
> The verbose output will tell - but you didn’t provide that.

sorry, you are right I did not provide the -vvv output. I tested this once again though and it showed that the copying

- **does not work** with **dest: " {{ item }} "**

# dest: " {{ item }} "

TASK [pgBackRest\_step\_install : install preps - push config file] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/gwagner/repos/ansible/step/roles/pgBackRest\_step\_install/tasks/main.yml:73  
\<vm-xzy.local\> ESTABLISH SSH CONNECTION FOR USER: stepuser  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o ‘ControlPath=“/home/gwagner/.ansible/cp/b5d05b761c”’ vm-xzy.local\> ‘/bin/sh -c ‘"’“‘echo ~stepuser && sleep 0’”’“‘’  
\<vm-xzy.local\> (0, b’/home/stepuser\n’, b’')  
\<vm-xzy.local\> ESTABLISH SSH CONNECTION FOR USER: stepuser  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o 'ControlPath=”/home/gwagner/.ansible/cp/b5d05b761c"’ vm-xzy.local\> ‘/bin/sh -c ‘"’"’( umask 77 && mkdir -p “`echo /home/stepuser/.ansible/tmp`”&& mkdir “`echo /home/stepuser/.ansible/tmp/ansible-tmp-1657880906.308936-536971-114267205405617`” && echo ansible-tmp-1657880906.308936-536971-114267205405617=“`echo /home/stepuser/.ansible/tmp/ansible-tmp-1657880906.308936-536971-114267205405617`” ) && sleep 0’“'”‘’  
\<vm-xzy.local\> (0, b’ansible-tmp-1657880906.308936-536971-114267205405617=/home/stepuser/.ansible/tmp/ansible-tmp-1657880906.308936-536971-114267205405617\n’, b’‘)  
Using module file /usr/lib/python3.8/site-packages/ansible/modules/stat.py  
\<vm-xzy.local\> PUT /home/gwagner/.ansible/tmp/ansible-local-5359602lbb241d/tmp4j\_zai9b TO /home/stepuser/.ansible/tmp/ansible-tmp-1657880906.308936-536971-114267205405617/AnsiballZ\_stat.py  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 sftp -o BatchMode=no -b - -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o ‘ControlPath=“/home/gwagner/.ansible/cp/b5d05b761c”’ ‘[vm-xzy.local\>]’  
\<vm-xzy.local\> (0, b’sftp\> put /home/gwagner/.ansible/tmp/ansible-local-5359602lbb241d/tmp4j\_zai9b /home/stepuser/.ansible/tmp/ansible-tmp-1657880906.308936-536971-114267205405617/AnsiballZ\_stat.py\n’, b’‘)  
\<vm-xzy.local\> ESTABLISH SSH CONNECTION FOR USER: stepuser  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o ‘ControlPath=“/home/gwagner/.ansible/cp/b5d05b761c”’ vm-xzy.local\> ‘/bin/sh -c ‘"’“‘chmod u+x /home/stepuser/.ansible/tmp/ansible-tmp-1657880906.308936-536971-114267205405617/ /home/stepuser/.ansible/tmp/ansible-tmp-1657880906.308936-536971-114267205405617/AnsiballZ\_stat.py && sleep 0’”’"’’  
\<vm-xzy.local\> (0, b’‘, b’‘)  
\<vm-xzy.local\> ESTABLISH SSH CONNECTION FOR USER: stepuser  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o ‘ControlPath=“/home/gwagner/.ansible/cp/b5d05b761c”’ -tt vm-xzy.local\> ‘/bin/sh -c ‘"’“'sudo -H -S -n -u root /bin/sh -c '”’"’“'”‘"’“'”‘“‘echo BECOME-SUCCESS-twlbdnfessfbowadgxwcufekdmtbfhqq ; /usr/libexec/platform-python /home/stepuser/.ansible/tmp/ansible-tmp-1657880906.308936-536971-114267205405617/AnsiballZ\_stat.py’”’“'”‘"’“'”‘"’“’ && sleep 0’”‘"’’  
Escalation succeeded  
\<vm-xzy.local\> (0, b’\r\n\r\n{“changed”: false, “stat”: {“exists”: true, “path”: " /etc/pgbackrest/pgbackrest.conf “, “mode”: “0640”, “isdir”: false, “ischr”: false, “isblk”: false, “isreg”: true, “isfifo”: false, “islnk”: false, “issock”: false, “uid”: 3354, “gid”: 20105, “size”: 739, “inode”: 182, “dev”: 64771, “nlink”: 1, “atime”: 1657802098.813018, “mtime”: 1657802008.0713508, “ctime”: 1657802008.333347, “wusr”: true, “rusr”: true, “xusr”: false, “wgrp”: false, “rgrp”: true, “xgrp”: false, “woth”: false, “roth”: false, “xoth”: false, “isuid”: false, “isgid”: false, “blocks”: 8, “block\_size”: 4096, “device\_type”: 0, “readable”: true, “writeable”: true, “executable”: false, “pw\_name”: “pgbackrest”, “gr\_name”: “pgbackrest”, “checksum”: “39b82b1660166f6852b5e1ae9cd7865a7a0cd390”, “mimetype”: “text/plain”, “charset”: “us-ascii”, “version”: “2016571620”, “attributes”: , “attr\_flags”: “”}, “invocation”: {“module\_args”: {“path”: " /etc/pgbackrest/pgbackrest.conf “, “follow”: false, “get\_checksum”: true, “checksum\_algorithm”: “sha1”, “get\_md5”: false, “get\_mime”: true, “get\_attributes”: true}}}\r\n’, b’Shared connection to vm-xzy.local\> closed.\r\n’)  
Using module file /usr/lib/python3.8/site-packages/ansible/modules/file.py  
\<vm-xzy.local\> PUT /home/gwagner/.ansible/tmp/ansible-local-5359602lbb241d/tmpv\_7q0zxq TO /home/stepuser/.ansible/tmp/ansible-tmp-1657880906.308936-536971-114267205405617/AnsiballZ\_file.py  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 sftp -o BatchMode=no -b - -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o 'ControlPath=”/home/gwagner/.ansible/cp/b5d05b761c”’ ‘[vm-xzy.local\>]’  
\<vm-xzy.local\> (0, b’sftp\> put /home/gwagner/.ansible/tmp/ansible-local-5359602lbb241d/tmpv\_7q0zxq /home/stepuser/.ansible/tmp/ansible-tmp-1657880906.308936-536971-114267205405617/AnsiballZ\_file.py\n’, b’‘)  
\<vm-xzy.local\> ESTABLISH SSH CONNECTION FOR USER: stepuser  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o ‘ControlPath=“/home/gwagner/.ansible/cp/b5d05b761c”’ vm-xzy.local\> ‘/bin/sh -c ‘"’“‘chmod u+x /home/stepuser/.ansible/tmp/ansible-tmp-1657880906.308936-536971-114267205405617/ /home/stepuser/.ansible/tmp/ansible-tmp-1657880906.308936-536971-114267205405617/AnsiballZ\_file.py && sleep 0’”’"’’  
\<vm-xzy.local\> (0, b’‘, b’‘)  
\<vm-xzy.local\> ESTABLISH SSH CONNECTION FOR USER: stepuser  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o ‘ControlPath=“/home/gwagner/.ansible/cp/b5d05b761c”’ -tt vm-xzy.local\> ‘/bin/sh -c ‘"’“'sudo -H -S -n -u root /bin/sh -c '”’"’“'”‘"’“'”‘“‘echo BECOME-SUCCESS-kkvidhgydqatjocboygqmuabzunhnmuh ; /usr/libexec/platform-python /home/stepuser/.ansible/tmp/ansible-tmp-1657880906.308936-536971-114267205405617/AnsiballZ\_file.py’”’“'”‘"’“'”‘"’“’ && sleep 0’”‘"’’  
Escalation succeeded  
\<vm-xzy.local\> (0, b’\r\n\r\n{“path”: " /etc/pgbackrest/pgbackrest.conf “, “changed”: false, “diff”: {“before”: {“path”: " /etc/pgbackrest/pgbackrest.conf “}, “after”: {“path”: " /etc/pgbackrest/pgbackrest.conf “}}, “uid”: 3354, “gid”: 20105, “owner”: “pgbackrest”, “group”: “pgbackrest”, “mode”: “0640”, “state”: “file”, “secontext”: “unconfined\_u:object\_r:user\_home\_t:s0”, “size”: 739, “invocation”: {“module\_args”: {“mode”: “0640”, “owner”: “pgbackrest”, “group”: “pgbackrest”, “dest”: " /etc/pgbackrest/pgbackrest.conf “, “\_original\_basename”: “repo\_pgbackrest.conf”, “recurse”: false, “state”: “file”, “path”: " /etc/pgbackrest/pgbackrest.conf “, “force”: false, “follow”: true, “modification\_time\_format”: “%Y%m%d%H%M.%S”, “access\_time\_format”: “%Y%m%d%H%M.%S”, “unsafe\_writes”: false, “\_diff\_peek”: null, “src”: null, “modification\_time”: null, “access\_time”: null, “seuser”: null, “serole”: null, “selevel”: null, “setype”: null, “attributes”: null}}}\r\n’, b’Shared connection to vm-xzy.local\> closed.\r\n’)  
\<vm-xzy.local\> ESTABLISH SSH CONNECTION FOR USER: stepuser  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o 'ControlPath=”/home/gwagner/.ansible/cp/b5d05b761c”’ vm-xzy.local\> '/bin/sh -c '”'”‘rm -f -r /home/stepuser/.ansible/tmp/ansible-tmp-1657880906.308936-536971-114267205405617/ \> /dev/null 2\>&1 && sleep 0’”‘"’’  
\<vm-xzy.local\> (0, b’‘, b’')  
ok: [vm-xzy.local\>] =\> (item=/etc/pgbackrest/pgbackrest.conf) =\> changed=false  
ansible\_loop\_var: item  
checksum: 39b82b1660166f6852b5e1ae9cd7865a7a0cd390  
dest: ’ /etc/pgbackrest/pgbackrest.conf ’  
diff:  
after:  
path: ’ /etc/pgbackrest/pgbackrest.conf ’  
before:  
path: ’ /etc/pgbackrest/pgbackrest.conf ’  
gid: 20105  
group: pgbackrest  
invocation:  
module\_args:  
\_diff\_peek: null  
\_original\_basename: repo\_pgbackrest.conf  
access\_time: null  
access\_time\_format: ‘%Y%m%d%H%M.%S’  
attributes: null  
dest: ’ /etc/pgbackrest/pgbackrest.conf ’  
follow: true  
force: false  
group: pgbackrest  
mode: ‘0640’  
modification\_time: null  
modification\_time\_format: ‘%Y%m%d%H%M.%S’  
owner: pgbackrest  
path: ’ /etc/pgbackrest/pgbackrest.conf ’  
recurse: false  
selevel: null  
serole: null  
setype: null  
seuser: null  
src: null  
state: file  
unsafe\_writes: false  
item: /etc/pgbackrest/pgbackrest.conf  
mode: ‘0640’  
owner: pgbackrest  
path: ’ /etc/pgbackrest/pgbackrest.conf ’  
secontext: unconfined\_u:object\_r:user\_home\_t:s0  
size: 739  
state: file

- **while it does work with**  **dest: “{{ item }}”**

TASK [pgBackRest\_step\_install : install preps - push config file] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/gwagner/repos/ansible/step/roles/pgBackRest\_step\_install/tasks/main.yml:73  
\<vm-xzy.local\> ESTABLISH SSH CONNECTION FOR USER: stepuser  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o ‘ControlPath=“/home/gwagner/.ansible/cp/b5d05b761c”’ vm-xzy.local\> ‘/bin/sh -c ‘"’“‘echo ~stepuser && sleep 0’”’“‘’  
\<vm-xzy.local\> (0, b’/home/stepuser\n’, b’')  
\<vm-xzy.local\> ESTABLISH SSH CONNECTION FOR USER: stepuser  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o 'ControlPath=”/home/gwagner/.ansible/cp/b5d05b761c"’ vm-xzy.local\> ‘/bin/sh -c ‘"’"’( umask 77 && mkdir -p “`echo /home/stepuser/.ansible/tmp`”&& mkdir “`echo /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813`” && echo ansible-tmp-1657881160.6701202-537076-79922878271813=“`echo /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813`” ) && sleep 0’“'”‘’  
\<vm-xzy.local\> (0, b’ansible-tmp-1657881160.6701202-537076-79922878271813=/home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813\n’, b’‘)  
Using module file /usr/lib/python3.8/site-packages/ansible/modules/stat.py  
\<vm-xzy.local\> PUT /home/gwagner/.ansible/tmp/ansible-local-537028rkexd51s/tmp7j0\_jskb TO /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/AnsiballZ\_stat.py  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 sftp -o BatchMode=no -b - -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o ‘ControlPath=“/home/gwagner/.ansible/cp/b5d05b761c”’ ‘[vm-xzy.local\>]’  
\<vm-xzy.local\> (0, b’sftp\> put /home/gwagner/.ansible/tmp/ansible-local-537028rkexd51s/tmp7j0\_jskb /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/AnsiballZ\_stat.py\n’, b’‘)  
\<vm-xzy.local\> ESTABLISH SSH CONNECTION FOR USER: stepuser  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o ‘ControlPath=“/home/gwagner/.ansible/cp/b5d05b761c”’ vm-xzy.local\> ‘/bin/sh -c ‘"’“‘chmod u+x /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/ /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/AnsiballZ\_stat.py && sleep 0’”’"’’  
\<vm-xzy.local\> (0, b’‘, b’‘)  
\<vm-xzy.local\> ESTABLISH SSH CONNECTION FOR USER: stepuser  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o ‘ControlPath=“/home/gwagner/.ansible/cp/b5d05b761c”’ -tt vm-xzy.local\> ‘/bin/sh -c ‘"’“'sudo -H -S -n -u root /bin/sh -c '”’"’“'”‘"’“'”‘“‘echo BECOME-SUCCESS-fvagnaiipacqngrattkmrszxxfkuhhor ; /usr/libexec/platform-python /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/AnsiballZ\_stat.py’”’“'”‘"’“'”‘"’“’ && sleep 0’”‘"’’  
Escalation succeeded  
\<vm-xzy.local\> (0, b’\r\n{“changed”: false, “stat”: {“exists”: false}, “invocation”: {“module\_args”: {“path”: “/etc/pgbackrest/pgbackrest.conf”, “follow”: false, “get\_checksum”: true, “checksum\_algorithm”: “sha1”, “get\_md5”: false, “get\_mime”: true, “get\_attributes”: true}}}\r\n’, b’Shared connection to vm-xzy.local\> closed.\r\n’)  
\<vm-xzy.local\> PUT /home/gwagner/repos/ansible/step/roles/pgBackRest\_step\_install/files/repo\_pgbackrest.conf TO /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/source  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 sftp -o BatchMode=no -b - -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o ‘ControlPath=“/home/gwagner/.ansible/cp/b5d05b761c”’ ‘[vm-xzy.local\>]’  
\<vm-xzy.local\> (0, b’sftp\> put /home/gwagner/repos/ansible/step/roles/pgBackRest\_step\_install/files/repo\_pgbackrest.conf /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/source\n’, b’‘)  
\<vm-xzy.local\> ESTABLISH SSH CONNECTION FOR USER: stepuser  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o ‘ControlPath=“/home/gwagner/.ansible/cp/b5d05b761c”’ vm-xzy.local\> ‘/bin/sh -c ‘"’“‘chmod u+x /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/ /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/source && sleep 0’”’"’’  
\<vm-xzy.local\> (0, b’‘, b’‘)  
Using module file /usr/lib/python3.8/site-packages/ansible/modules/copy.py  
\<vm-xzy.local\> PUT /home/gwagner/.ansible/tmp/ansible-local-537028rkexd51s/tmpod2bbp87 TO /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/AnsiballZ\_copy.py  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 sftp -o BatchMode=no -b - -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o ‘ControlPath=“/home/gwagner/.ansible/cp/b5d05b761c”’ ‘[vm-xzy.local\>]’  
\<vm-xzy.local\> (0, b’sftp\> put /home/gwagner/.ansible/tmp/ansible-local-537028rkexd51s/tmpod2bbp87 /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/AnsiballZ\_copy.py\n’, b’‘)  
\<vm-xzy.local\> ESTABLISH SSH CONNECTION FOR USER: stepuser  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o ‘ControlPath=“/home/gwagner/.ansible/cp/b5d05b761c”’ vm-xzy.local\> ‘/bin/sh -c ‘"’“‘chmod u+x /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/ /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/AnsiballZ\_copy.py && sleep 0’”’"’’  
\<vm-xzy.local\> (0, b’‘, b’‘)  
\<vm-xzy.local\> ESTABLISH SSH CONNECTION FOR USER: stepuser  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o ‘ControlPath=“/home/gwagner/.ansible/cp/b5d05b761c”’ -tt vm-xzy.local\> ‘/bin/sh -c ‘"’“'sudo -H -S -n -u root /bin/sh -c '”’"’“'”‘"’“'”‘“‘echo BECOME-SUCCESS-jrfmzdhcxkipllgmwwxlrjbkwivzfjli ; /usr/libexec/platform-python /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/AnsiballZ\_copy.py’”’“'”‘"’“'”‘"’“’ && sleep 0’”‘"’’  
Escalation succeeded  
\<vm-xzy.local\> (0, b’\r\n\r\n{“dest”: “/etc/pgbackrest/pgbackrest.conf”, “src”: “/home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/source”, “md5sum”: “f5f410521b8c111536934fdad55902ea”, “checksum”: “39b82b1660166f6852b5e1ae9cd7865a7a0cd390”, “changed”: true, “uid”: 3354, “gid”: 20105, “owner”: “pgbackrest”, “group”: “pgbackrest”, “mode”: “0640”, “state”: “file”, “secontext”: “system\_u:object\_r:etc\_t:s0”, “size”: 739, “invocation”: {“module\_args”: {“src”: “/home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/source”, “dest”: “/etc/pgbackrest/pgbackrest.conf”, “mode”: “0640”, “owner”: “pgbackrest”, “group”: “pgbackrest”, “\_original\_basename”: “repo\_pgbackrest.conf”, “follow”: false, “checksum”: “39b82b1660166f6852b5e1ae9cd7865a7a0cd390”, “backup”: false, “force”: true, “unsafe\_writes”: false, “content”: null, “validate”: null, “directory\_mode”: null, “remote\_src”: null, “local\_follow”: null, “seuser”: null, “serole”: null, “selevel”: null, “setype”: null, “attributes”: null}}}\r\n’, b’Shared connection to vm-xzy.local\> closed.\r\n’)  
\<vm-xzy.local\> ESTABLISH SSH CONNECTION FOR USER: stepuser  
\<vm-xzy.local\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ‘User=“stepuser”’ -o ConnectTimeout=10 -o ‘ControlPath=“/home/gwagner/.ansible/cp/b5d05b761c”’ vm-xzy.local\> ‘/bin/sh -c ‘"’“‘rm -f -r /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/ \> /dev/null 2\>&1 && sleep 0’”’"‘’  
\<vm-xzy.local\> (0, b’‘, b’')  
changed: [vm-xzy.local\>] =\> (item=/etc/pgbackrest/pgbackrest.conf) =\> changed=true  
ansible\_loop\_var: item  
checksum: 39b82b1660166f6852b5e1ae9cd7865a7a0cd390  
dest: /etc/pgbackrest/pgbackrest.conf  
diff:   
gid: 20105  
group: pgbackrest  
invocation:  
module\_args:  
\_original\_basename: repo\_pgbackrest.conf  
attributes: null  
backup: false  
checksum: 39b82b1660166f6852b5e1ae9cd7865a7a0cd390  
content: null  
dest: /etc/pgbackrest/pgbackrest.conf  
directory\_mode: null  
follow: false  
force: true  
group: pgbackrest  
local\_follow: null  
mode: ‘0640’  
owner: pgbackrest  
remote\_src: null  
selevel: null  
serole: null  
setype: null  
seuser: null  
src: /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/source  
unsafe\_writes: false  
validate: null  
item: /etc/pgbackrest/pgbackrest.conf  
md5sum: f5f410521b8c111536934fdad55902ea  
mode: ‘0640’  
owner: pgbackrest  
secontext: system\_u:object\_r:etc\_t:s0  
size: 739  
src: /home/stepuser/.ansible/tmp/ansible-tmp-1657881160.6701202-537076-79922878271813/source  
state: file  
uid: 3354

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [July 17, 2022, 7:11am UTC](https://forum.ansible.com/t/copy-task-wont-copy-a-file-eventhough-reporting-ok/36850/8 "2022-07-17T07:11:35Z")

</div>

Hi

> sorry, you are right I did not provide the -vvv output. I tested this once again though and it showed that the copying
> 
> does not work with dest: " {{ item }} "

I think your definition of "it works" is incorrect, see below

.....

> \<vm-xzy.local\> ESTABLISH SSH CONNECTION FOR USER: stepuser  
> \<vm-xzy.local\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="stepuser"' -o ConnectTimeout=10 -o 'ControlPath="/home/gwagner/.ansible/cp/b5d05b761c"' vm-xzy.local\> '/bin/sh -c '"'"'rm -f -r /home/stepuser/.ansible/tmp/ansible-tmp-1657880906.308936-536971-114267205405617/ \> /dev/null 2\>&1 && sleep 0'"'"''  
> \<vm-xzy.local\> (0, b'', b'')  
> ok: [vm-xzy.local\>] =\> (item=/etc/pgbackrest/pgbackrest.conf) =\> changed=false

^^^ This clearly says "ok" so as far as ansible is concerned, things \*did\* work.  
It's not what you expected, but that's because you didn't give ansible  
the correct input.  
Your loop item is a string that starts with a slash, which, if used as  
'dest' parameter for the copy command, is considered an absolute path.  
But because of your superfluous spaces it will be considered a \*relative\* path.  
Ansible will try to copy the file to that path, and according to your  
logs, that was successful.  
It doesn't actually list the full path, but from the logs it will  
likely be '/home/stepuser/ /etc/pgbackrest/pgbackrest.conf '.  
Note that this includes a directory with a name that is just a space,  
which, depending on your shell setup, is not easy to spot - especially  
if you don't expect it.  
Also the file name will have a trailing space.

One strange thing is that the copy module does not create any parent  
directory structures for files, so I wonder how that got created.

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [July 18, 2022, 12:24pm UTC](https://forum.ansible.com/t/copy-task-wont-copy-a-file-eventhough-reporting-ok/36850/9 "2022-07-18T12:24:16Z")

</div>

> It doesn't actually list the full path, but from the logs it will  
> likely be '/home/stepuser/ /etc/pgbackrest/pgbackrest.conf '.  
> Note that this includes a directory with a name that is just a space,  
> which, depending on your shell setup, is not easy to spot - especially  
> if you don't expect it. Also the file name will have a trailing space.

spot on, thx for the explanation. I didn't use Ansible for a couple of months and it seems getting back on the horse takes a litte time just for getting the essentials back up'n'running

> One strange thing is that the copy module does not create any parent  
> directory structures for files, so I wonder how that got created.

I ran this and other variants of the TASK a couple of times against that host. So, maybe in one of those rounds the directory somehow got created accidentally.
