Bootstrap FreeKB - Ansible - ansible ad hoc copy command
Ansible - ansible ad hoc copy command

Updated:   |  Ansible articles

The ansible ad-hoc command can use the copy module to copy a file or directory from the control node (that's your Ansible server) to the managed nodes (e.g. target systems). The remote_src parameter can be used to copy a file or directory on the managed node to some other directory on the managed node.

The get_url module can be used to copy a file from a remote URL to the managed node.

The ansible-doc copy command can be used to show the Ansible documention on the copy module.


Copy file from control node to managed nodes

In this example, /tmp/foo.txt on the control node is copied to /tmp/foo.txt on the managed nodes.

ansible all --module-name copy --args "src=/tmp/foo.txt dest=/tmp/foo.txt"

 


Copy file from control node to managed nodes

The remote_src parameter can be used to copy a file on the managed node to some other directory on the managed node.

ansible all --module-name copy --args "src=/tmp/foo.txt dest=/tmp/foo.txt remote_src=true"

 

Something like this should be returned.

server1.example.com | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": true,
    "checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
    "dest": "/tmp/foo.txt",
    "gid": 1000,
    "group": "admins",
    "md5sum": "d41d8cd98f00b204e9800998ecf8427e",
    "mode": "0664",
    "owner": "john.doe",
    "secontext": "unconfined_u:object_r:user_home_t:s0",
    "size": 0,
    "src": "/home/john.doe/.ansible/tmp/ansible-tmp-1616323288.633544-21966-222592565594527/source",
    "state": "file",
    "uid": 1000
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter cf2dd3 in the box below so that we can be sure you are a human.