How to use scp command with raw module of Ansible to transfer file to remote hosts

ansible

How to use scp command with raw module of Ansible to transfer file to remote hosts

I am a beginner to ansible.

I am trying to copy a file from ansible-master to ansible managed nodes using raw module and executing scp command.

Here's the ad-hoc ansible command i used to get result

ansible 192.168.0.5 -m raw -a "scp /home/osboxes/test osboxes@192.168.0.5:/home/"

Can anybody help me out over here, what's wrong in above command and what needs to be done to get the desired results

Best Answer

What I read from your command is, in my not-so-good English:

Please, host with 192.168.0.5 address, execute the scp command to copy the /home/osboxes/test file to yourself entering with the user osboxes and locating the copy in the usually avoided for user writings /home directory

If you really want to do that, please make sure that:

  • The file /home/osboxes/test exists in /home/osboxes of the host 192.168.0.5
  • The user osboxes has write permissions in the /home directory.

If you want to copy the file from 192.168.0.5 to another host, let's say, 192.168.0.6, and you want to put it in the home directory of osboxes, consider this command:

ansible 192.168.0.5 -m raw -a "scp /home/osboxes/test osboxes@192.168.0.6:"

Hope this helps