Ansible (12) file module, ansible12file Module
File Module
Before the ansible command line, there was a copy module. In the era of playbook, there was also a module dedicated to copying files. Of course, this era is not just as simple as copying files.
Official explanations:
The file module contains the creation, copying, moving, and deletion operations of files, folders, and hyperlink classes.
Common Parameters
Parameter Name |
Required? |
Default Value |
Option |
Description |
Follow |
No |
No |
Yes/no |
If the original file is a link, it is still a link after the copy. |
Force |
No |
No |
Yes/no |
Enforced, not mentioned |
Group |
No |
|
|
Sets the permission for a group to copy files to a remote node. |
Mode |
No |
|
|
Equivalent to chmod, the parameter can be "u + rwx or u = rw, g = r, o = r" |
Owner |
No |
|
|
Sets the permission for a user to copy files to a remote node. |
Path |
Yes |
|
|
Target path, which can also be replaced by dest and name |
Src |
Yes |
|
|
The original location of the file/folder to be copied. |
State |
No |
File |
File/link/directory/hard/touch/absent |
File indicates that a file is copied, link indicates that a soft link is finally made, directory indicates a folder, hard indicates a hard link, touch indicates that an empty file is generated, and absent indicates that a file is deleted. |
Case
# Modify all groups, persons, and permissions of files. -File: path =/etc/foo. conf owner = foo group = foo mode = 0644 # operation link case-file: src =/file/to/link/to dest =/path/to/symlink owner = foo group = foo state = link # parameterized case-file: src =/tmp/{item. path} dest = {item. dest} state = link with_items:-{path: 'X', dest: 'y'}-{path: 'Z', dest: 'K'} # use touch to create an empty file and define the permission-file: path =/etc/foo. conf state = touch mode = "u = rw, g = r, o = r" # touch an empty file and modify the permission-file: path =/etc/foo. conf state = touch mode = "u + rw, g-wx, o-rwx"
How? Is it similar to copy?