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:
Key | Returned | Description |
---|---|---|
backup_file
string
|
changed and if backup=yes |
Name of backup file created
Sample:
/path/to/[email protected]:09~
|
checksum
string
|
success |
SHA1 checksum of the file after running copy
Sample:
6e642bb8dd5c2e027bf21dd923337cbb4214f827
|
dest
string
|
success |
Destination file/path
Sample:
/path/to/file.txt
|
gid
integer
|
success |
Group id of the file, after execution
Sample:
100
|
group
string
|
success |
Group of the file, after execution
Sample:
httpd
|
md5sum
string
|
when supported |
MD5 checksum of the file after running copy
Sample:
2a5aeecc61dc98c4d780b14b330e3282
|
mode
string
|
success |
Permissions of the target, after execution
Sample:
420
|
owner
string
|
success |
Owner of the file, after execution
Sample:
httpd
|
size
integer
|
success |
Size of the target, after execution
Sample:
1220
|
src
string
|
changed |
Source file used for the copy on the target machine
Sample:
/home/httpd/.ansible/tmp/ansible-tmp-1423796390.97-147729857856000/source
|
state
string
|
success |
State of the target, after execution
Sample:
file
|
uid
integer
|
success |
Owner id of the file, after execution
Sample:
100
|
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.