文件模块
序号 | 模块名 | 英文解释 | 中文说明 |
---|---|---|---|
1 | acl | Sets and retrieves file ACL information | - |
2 | archive | Creates a compressed archive of one or more files or trees | 压缩文件 |
3 | assemble | Assembles a configuration file from fragments | - |
4 | blockinfile | Insert/update/remove a text block surrounded by marker lines | - |
5 | copy | Copies files to remote locations | 拷贝文件 |
6 | fetch | Fetches a file from remote nodes | 从远程节点拉取一个文件 |
7 | file | Sets attributes of files | 给文件设置属性 |
8 | find | Return a list of files based on specific criteria | - |
9 | ini_file | Tweak settings in INI files | - |
10 | iso_extract | Extract files from an ISO image | - |
11 | lineinfile | Ensure a particular line is in a file, or replace an existing line using a back-referenced regular expression | – |
12 | patch | Apply patch files using the GNU patch tool | - |
13 | replace | Replace all instances of a particular string in a file using a back-referenced regular expression | - |
14 | stat | Retrieve file or file system status | - |
15 | synchronize | A wrapper around rsync to make common tasks in your playbooks quick and easy | - |
16 | tempfile | Creates temporary files and directories | - |
17 | template | Templates a file out to a remote server | - |
18 | unarchive | Unpacks an archive after (optionally) copying it from the local machine | 解压一个从本地拷贝的文件 |
19 | xattr | set/retrieve extended attributes | - |
20 | xml | Manage bits and pieces of XML files or strings | - |
示例
acl
1 | # Grant user Joe read access to a file |
archive
1 | # Compress directory /path/to/foo/ into /path/to/foo.tgz |
assemble
1 | # Example from Ansible Playbooks |
blockinfile
1 | # Before 2.3, option 'dest' or 'name' was used instead of 'path' |
copy
1 | # Example from Ansible Playbooks |
fetch
1 | # Store file into /tmp/fetched/host.example.com/tmp/somefile |
file
1 | # change file ownership, group and mode. When specifying mode using octal numbers, first digit should always be 0. |
find
1 | - name: Recursively find /tmp files older than 2 days |
ini_file
1 | # Before 2.3, option 'dest' was used instead of 'path' |
iso_extract
1 | - name: Extract kernel and ramdisk from a LiveCD |
lineinfile
1 | # Before 2.3, option 'dest', 'destfile' or 'name' was used instead of 'path' |
patch
1 | - name: Apply patch to one file |
replace
1 | # Before 2.3, option 'dest', 'destfile' or 'name' was used instead of 'path' |
stat
1 | # Obtain the stats of /etc/foo.conf, and check that the file still belongs |
synchronize
1 | # Synchronization of src on the control machine to dest on the remote hosts |
tempfile
1 | - name: create temporary build directory |
template
1 | # Example from Ansible Playbooks |
unarchive
1 | - name: Extract foo.tgz into /var/lib/foo |
xattr
1 | # Obtain the extended attributes of /etc/foo.conf |
xml
1 | - name: Remove the subjective attribute of the rating element |
更多详情参考官网