community.openwrt.copy module – Copy files to remote OpenWrt devices
Note
This module is part of the community.openwrt collection (version 0.5.0).
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install community.openwrt.
To use it in a playbook, specify: community.openwrt.copy.
Synopsis
The community.openwrt.copy module copies a file from the Ansible controller to remote OpenWrt devices.
The
contentparameter supports Jinja2 variable interpolation.
Note
This module has a corresponding action plugin.
Parameters
Parameter |
Comments |
|---|---|
Create a backup file including the timestamp information so you can get the original file back if you clobbered it incorrectly. Choices:
|
|
Remote absolute path where the file is copied to. If If If The parent directory of |
|
Determines whether the remote file must always be replaced. If If Choices:
|
|
Group name that should own the file or directory. Passed directly to the If not specified, group ownership is not changed. Not applied to symlinks when |
|
Permissions for the file or directory. Can be specified as an octal number (for example, When using octal notation, quote the value to ensure it is treated as a string. If not specified, permissions may be determined by the system default Not applied to symlinks when |
|
User name that should own the file or directory. Passed directly to the If not specified, ownership is not changed. Not applied to symlinks when |
|
Local path to a file to copy to the remote server. Can be absolute or relative. When relative, the file is searched in the Only regular files are supported. Directories cannot be copied recursively. Do not specify together with |
|
Command to run to validate the file before copying it into place. The file path is substituted for The command must include The command is executed through If the validation command fails, the copy operation is aborted. |
Attributes
Attribute |
Support |
Description |
|---|---|---|
Support: full |
Can run in |
|
Support: full |
Returns details on what has changed (or possibly needs changing in |
|
Platform: OpenWrt |
Target platform for this module. |
|
Support: none This module uses basic shell commands for file operations and does not implement Ansible’s atomic file operation functions. |
Uses Ansible’s strict file operation functions to ensure proper permissions and avoid data corruption. |
Notes
Note
This module does not support recursive directory copy. Only regular files can be copied.
Supports
check_mode.
Examples
- name: Copy file with owner and permissions
community.openwrt.copy:
src: /srv/myfiles/foo.conf
dest: /etc/foo.conf
owner: root
group: root
mode: '0644'
- name: Copy file from controller, creating backup
community.openwrt.copy:
src: /mine/ntp.conf
dest: /etc/ntp.conf
owner: root
group: root
mode: '0644'
backup: true
- name: Copy inline content to file
community.openwrt.copy:
content: |
# Managed by Ansible
option enabled '1'
option hostname 'openwrt'
dest: /etc/config/system
mode: '0644'
- name: Copy file only if it does not exist
community.openwrt.copy:
src: /srv/myfiles/foo.conf
dest: /etc/foo.conf
force: false
- name: Copy file and validate
community.openwrt.copy:
src: /etc/uci-defaults/template
dest: /etc/uci-defaults/custom
validate: sh -n %s
- name: Copy file from Ansible files directory
community.openwrt.copy:
src: myconfig.txt
dest: /etc/config/myapp
mode: '0600'
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
|---|---|
Name of backup file created. Returned: changed and if backup=true Sample: |
|
SHA1 checksum of the source file. Returned: success Sample: |
|
Destination file/path. Returned: success Sample: |
|
MD5 checksum of the source file. Returned: when supported Sample: |
|
Source file used for the copy on the target machine. After the action plugin transfers the file, this is the path on the remote device. Returned: changed Sample: |
|
State of the target file after execution. Returned: success Sample: |