File module
In the previous ansible command line when there is a copy module, in the era of playbook naturally also have a module dedicated to file copy, of course, it is not only a copy of the file so simple.
From the official explanation:
The file module contains the creation, copying, movement, and deletion of files, folders, and Hyperlink classes.
Common parameters
Name of parameter |
whether you must |
Default Value |
Options |
Description |
Follow |
No |
No |
Yes/no |
If the original file is link, the copy is still link |
Force |
No |
No |
Yes/no |
Forced execution, didn't see? |
Group |
No |
|
|
Set a group to have file permissions for copying to a remote node |
Mode |
No |
|
|
Equivalent to chmod, parameter can be "u+rwx or u=rw,g=r,o=r" |
Owner |
No |
|
|
Set the file permissions that a user has copied to the remote node |
Path |
Yes |
|
|
The target path can also be replaced with Dest,name |
Src |
Yes |
|
|
The original location of the file/folder to be copied. |
State |
No |
File |
File/link/directory/hard/touch/absent |
File represents a copy of the document, the link represents the end of a soft link; directory represents a folder; hard links; Touch represents an empty file; Absent represents the deletion. |
Case
# Modify all groups, people, and permissions for a file. - file: path=/etc/foo. conf owner=foo group=foo mode=0644 # Action Link case- file: src=/file/to/link/to dest=/path/to/symlink owner=foo Group=foo State=link #参数化案例- file: src=/tmp/{{Item.path}} dest={{item.dest}} state=linkWith_items:-{ path: ' x ', dest: ' y ' }-{ path: ' z ', dest: ' K ' }# Use Touch to create an empty file and define permissions- file: path=/etc/fooconf state=touch mode="U=rw,g=r,o=r" # Touch an empty file, and modify permissions- file: path=/etc/fooconf state=touch mode="u+rw,g-wx,o-rwx"
How is it? Is it similar to copy?
Ansible () file module