Author: | Michael DeHaan |
---|
parameter | required | default | choices | comments |
---|---|---|---|---|
backup | no | no |
|
Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly. (added in Ansible 0.7) |
content | no | When used instead of 'src', sets the contents of a file directly to the specified value. (added in Ansible 1.1) | ||
dest | yes | Remote absolute path where the file should be copied to. If src is a directory, this must be a directory too. | ||
directory_mode | no | When doing a recursive copy set the mode for the directories. If this is not set we will default the system defaults. (added in Ansible 1.5) | ||
force | no | yes |
|
the default is yes , which will replace the remote file when contents are different than the source. If no , the file will only be transferred if the destination does not exist. (added in Ansible 1.1) |
group | no | name of the group that should own the file/directory, as would be fed to chown | ||
mode | no | mode the file or directory should be, such as 0644 as would be fed to chmod | ||
owner | no | name of the user that should own the file/directory, as would be fed to chown | ||
recurse | no | Copy all contents in the source directory recursively. This will be slightly inefficient compared to the 'synchronize' module and should not be used for large directory trees. | ||
selevel | no | s0 | level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the range . _default feature works as for seuser. |
|
serole | no | role part of SELinux file context, _default feature works as for seuser. |
||
setype | no | type part of SELinux file context, _default feature works as for seuser. |
||
seuser | no | user part of SELinux file context. Will default to system policy, if applicable. If set to _default , it will use the user portion of the policy if available |
||
src | no | Local path to a file to copy to the remote server; can be absolute or relative. If path is a directory, it is copied recursively. In this case, if path ends with "/", only inside contents of that directory are copied to destination. Otherwise, if it does not end with "/", the directory itself with all contents is copied. This behavior is similar to Rsync. | ||
validate | no | The validation command to run before copying into place. The path to the file to validate is passed in via '%s' which must be present as in the visudo example below. The command is passed securely so shell features like expansion and pipes won't work. (added in Ansible 1.2) |
# Example from Ansible Playbooks
- copy: src=/srv/myfiles/foo.conf dest=/etc/foo.conf owner=foo group=foo mode=0644
# 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=644 backup=yes
# Copy a new "sudoers" file into place, after passing validation with visudo
- copy: src=/mine/sudoers dest=/etc/sudoers validate='visudo -cf %s'
Note
The “copy” module recursively copy facility does not scale to lots (>hundreds) of files. For alternative, see synchronize module, which is a wrapper around rsync.