path:指明要操作的对象[文件或目录]。
state:
state=directory:创建的是一个目录文件。
state=touch:创建的是一个普通文件。
state=link:创建的是一个软连接。
state=hard:创建的是一个硬链接。
state=absent:删除普通文件或是目录问文件。
src:当state=link或是state=hard时,需要指明链接的是哪个文件,通过src参数即可指定链接源。
force : 当state=link的时候,可配合此参数强制创建链接文件。force=yes时,表示强制创建链接文件,不过强制创建链接文件分为第三种情况。
owner :用于指定被操作文件的属主,属主对应的用户必须在远程主机中存在,否则会报错。
group :用于指定被操作文件的属组,属组对应的组必须在远程主机中存在,否则会报错。
mode:用于指定被操作文件的权限。
recurse:当要操作的文件为目录,将recurse设置为yes,可以递归的修改目录中文件的属性。
1、创建一个普通文件。
ansible box -m file -a "path=/home/box/test01 state=touch"
2、创建一个目录文件。
ansible box -m file -a "path=/home/box/ state=directory"
3、删除一个文件。
ansible box -m file -a "path=/home/box/ state=absent"
4、修改文件属性。
anisble box -m file -a ‘path=/home/box/test01 owner=test01 group=test01 mode=0755‘
5、递归修改属性
anisble box -m file -a ‘path=/home/box/ owner=test01 group=test01 mode=0755 recurse=yes‘
6、强制创建软l链接文件。
anisble box -m file -a ‘path=/home/box/test01 src=/tmp/test_link force‘
原文:https://www.cnblogs.com/lizhibox/p/14742125.html