copy – Copy files to remote locations¶
Synopsis¶
- The
copy
module copies a file from the local or remote machine to a location on the remote machine. - Use the fetch module to copy files from remote locations to the local box.
- If you need variable interpolation in copied files, use the template module. Using a variable in the
content
field will result in unpredictable output. - For Windows targets, use the win_copy module instead.
Parameters¶
See Also¶
See also
- assemble – Assemble configuration files from fragments
- The official documentation on the assemble module.
- fetch – Fetch files from remote nodes
- The official documentation on the fetch module.
- file – Manage files and file properties
- The official documentation on the file module.
- synchronize – A wrapper around rsync to make common tasks in your playbooks quick and easy
- The official documentation on the synchronize module.
- template – Template a file out to a remote server
- The official documentation on the template module.
- win_copy – Copies files to remote locations on windows hosts
- The official documentation on the win_copy module.
Examples¶
- name: Copy file with owner and permissions
copy:
src: /srv/myfiles/foo.conf
dest: /etc/foo.conf
owner: foo
group: foo
mode: '0644'
- name: Copy file with owner and permission, using symbolic representation
copy:
src: /srv/myfiles/foo.conf
dest: /etc/foo.conf
owner: foo
group: foo
mode: u=rw,g=r,o=r
- name: Another symbolic mode example, adding some permissions and removing others
copy:
src: /srv/myfiles/foo.conf
dest: /etc/foo.conf
owner: foo
group: foo
mode: u+rw,g-wx,o-rwx
- name: Copy a new "ntp.conf file into place, backing up the original if it differs from the copied version
copy:
src: /mine/ntp.conf
dest: /etc/ntp.conf
owner: root
group: root
mode: '0644'
backup: yes
- name: Copy a new "sudoers" file into place, after passing validation with visudo
copy:
src: /mine/sudoers
dest: /etc/sudoers
validate: /usr/sbin/visudo -csf %s
- name: Copy a "sudoers" file on the remote machine for editing
copy:
src: /etc/sudoers
dest: /etc/sudoers.edit
remote_src: yes
validate: /usr/sbin/visudo -csf %s
- name: Copy using inline content
copy:
content: '# This file was moved to /etc/other.conf'
dest: /etc/mine.conf
- name: If follow=yes, /path/to/file will be overwritten by contents of foo.conf
copy:
src: /etc/foo.conf
dest: /path/to/link # link to /path/to/file
follow: yes
- name: If follow=no, /path/to/link will become a file and be overwritten by contents of foo.conf
copy:
src: /etc/foo.conf
dest: /path/to/link # link to /path/to/file
follow: no
Return Values¶
Common return values are documented here, the following are the fields unique to this module:
Status¶
- This module is guaranteed to have backward compatible interface changes going forward. [stableinterface]
- This module is maintained by the Ansible Core Team. [core]
Red Hat Support¶
More information about Red Hat’s support of this module is available from this Red Hat Knowledge Base article.
Authors¶
- Ansible Core Team
- Michael DeHaan
Hint
If you notice any issues in this documentation, you can edit this document to improve it.