Copy module can't find file, but normal cp command works correctly

156 views
Skip to first unread message

Colin L

unread,
Aug 29, 2017, 1:58:21 PM8/29/17
to Ansible Project
Hello,

I am trying to use the copy module to do a simple copy; but I am getting an error that has me puzzled:

Error that I get:

AnsibleFileNotFound: Could not find or access '/root/Downloads/example.desktop'

I have checked permissions, and that doesn't seem to be an issue, so to do some testing I tried the exact same parameters for the standard cp command.

YML file:

---
  - name: Ansible testing tasks
    hosts: 'test_servers'

    tasks:

    - name: Copying DIAMD desktop
      shell: cp /root/Downloads/DIAMD.desktop /etc/skel/Desktop/DIAMD.desktop
    # This one works#

      - name: creating desktop icons
        copy:
         src: /root/Downloads/example.desktop
         dest: /etc/skel/Desktop/example.desktop
     #this one doesn't work#


Trace output showing errors:

changed: [localhost] => {
    "changed": true,
    "cmd": "cp /root/Downloads/example.desktop /etc/skel/Desktop/example.desktop",
    "delta": "0:00:00.008886",
    "end": "2017-08-29 11:55:06.523320",
    "failed": false,
    "invocation": {
        "module_args": {
            "_raw_params": "cp /root/Downloads/example.desktop /etc/skel/Desktop/example.desktop",
            "_uses_shell": true,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "warn": true
        }
    },
    "rc": 0,
    "start": "2017-08-29 11:55:06.514434",
    "stderr": "",
    "stderr_lines": [],
    "stdout": "",
    "stdout_lines": []
}

TASK [creating desktop icons] **************************************************************************************************************************************************
task path: /home/n8427a/playbooks/testing.yml:13
The full traceback is:
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/ansible-2.4.0-py2.6.egg/ansible/plugins/action/copy.py", line 457, in run
    source = self._find_needle('files', source)
  File "/usr/lib/python2.6/site-packages/ansible-2.4.0-py2.6.egg/ansible/plugins/action/__init__.py", line 982, in _find_needle
    return self._loader.path_dwim_relative_stack(path_stack, dirname, needle)
  File "/usr/lib/python2.6/site-packages/ansible-2.4.0-py2.6.egg/ansible/parsing/dataloader.py", line 404, in path_dwim_relative_stack
    raise AnsibleFileNotFound(file_name=source, paths=[to_text(p) for p in search])
AnsibleFileNotFound: Could not find or access '/root/Downloads/example.desktop'

fatal: [localhost]: FAILED! => {
    "changed": false,
    "failed": true,
    "msg": "Could not find or access '/root/Downloads/example.desktop'"
}


I would believe that if the standard cp command worked, then the copy module would also be able to find the command.
#note, I am running command as root,


Any thoughts?

Thanks,
Colin

Matt Martz

unread,
Aug 29, 2017, 2:21:19 PM8/29/17
to ansible...@googlegroups.com
The `copy` module defaults from copying from the ansible controller to the remote target.

To do a copy with a remote src, use the `remote_src` option

--
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/1f90a604-ad9e-40ce-a991-f06b172142df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Matt Martz
@sivel
sivel.net

Colin L

unread,
Aug 29, 2017, 3:03:15 PM8/29/17
to Ansible Project
Thank you Matt.

It would appear that I didn't RTFM.
Reply all
Reply to author
Forward
0 new messages