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 -m raw -a "scp /home/osboxes/test osboxes@"

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

  • 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

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

Please, host with 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
  • The user osboxes has write permissions in the /home directory.

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

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

Hope this helps

  • hi there, in this command "ansible -m raw -a "scp /home/osboxes/test osboxes@"" after ansible that ip( 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: to target node . – 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 Please check the output of ansible -a "uname -a" and if is in the inventory (check /etc/ansible/hosts) you should see the data from – 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@" – J.M. Robles May 10 '20 at 16:34

used shell

shell: scp /home/osboxes/test osboxes@

  • 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.