2

I need to copy a file from /root of ansible control node to remote node's /root.

I am able to copy that file if i keep it at any other location (say /tmp) of control node and able to copy it to /root of remote node (since i mentioned become in ansible.cfg )

But how to copy file from /root of ansible control node to remote node's /root ?

It gives error as

'fatal: [testserver]: FAILED! => {"changed": false, "msg": "Could not find or access '/root/abc.txt' on the Ansible Controller'

Please note, file exists at /root/ of controller.

thanks,

Smily
  • 2,308
  • 2
  • 17
  • 41
pratkul007
  • 89
  • 1
  • 6

1 Answers1

1

To access a file in /root on the controller you need to be.... root on the controller. But running your playbook as root on the controller is not really a good idea. If your current user has the necessary rights on localhost for privilege escalation, a possible scenario would be.

  1. use privilege escalation on localhost to copy the file or grab file content in a variable.
  2. copy the resulting file or content to the target host.
  3. if you copied the file, remove the copy.

Note: if you put the file in /root for privacy/security reasons, a much better option would be to store this file encrypted with ansible-vault directly in your project.

Zeitounator
  • 38,476
  • 7
  • 53
  • 66