0

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

2
  • 1
    Use 'scp' without Ansible or use 'copy' module when you want to use Ansible. Ansible raw and scp don't make sense. – Vladimir Botka May 10 '20 at 7:11
  • AFAIK the main purpose of the raw module is to install Python to be able to use other modules. Is there any reason to use the raw module? – Henrik Pingel May 10 '20 at 7:38
0

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

3
  • hi there, in this command "ansible 192.168.0.5 -m raw -a "scp /home/osboxes/test osboxes@192.168.0.5:/home/"" after ansible that ip(192.168.0.5) itself is the target node where file needs to be copied according to ansible syntax. In ansible any target node which doesn't have python installed, we need to use raw module of anisble to execute tasks on those target nodes. So i'm searching for right syntax of scp command of raw module to achieve above scenario of coping files from source(my ansible master ip:192.168.0.3) to target node 192.168.0.5 . – james May 10 '20 at 7:11
  • In the command ansible <host pattern> -a '<command>' you are using the default module raw to make the command <command> be executed in <host pattern>. You must grant the presence of <host pattern> in the inventory file. I so, you are saying that scp must be executed in 192.168.0.5. Please check the output of ansible 192.168.0.5 -a "uname -a" and if 192.168.0.5 is in the inventory (check /etc/ansible/hosts) you should see the data from 192.168.0.5 – J.M. Robles May 10 '20 at 16:22
  • As localhost is available though it is not explicitely in the inventory, if your test file is in the host where you execute ansible from, you could do ansible localhost -a "scp /home/osboxes/test osboxes@192.168.0.5:/home/" – J.M. Robles May 10 '20 at 16:34
0

used shell

shell: scp /home/osboxes/test osboxes@192.168.0.6:

1
  • please explain more and not just paste a short text without context – djdomi Jul 22 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.