ansible模块--file模块

网友投稿 1221 2022-10-10

ansible模块--file模块

ansible模块--file模块

创建或者和删除远程主机上的文件或者目录

path 指定文件 如果远程主机上没有该文件,则进行创建state 创建类型 touch 文件 directory 目录

state=absent 删除文件或者目录

link 软连接 src=源文件名 path=目标链接文件名hard 硬链接 src=源文件名 path=目标链接文件名

以下三个参数,既可以修改,也可以自动添加mod:权限 可以在添加时设置特殊权限,前提要有执行权限( set 粘滞位)owner:属主

group:属组

1.创建一个普通文件

[root@ansible ~]# ansible mysql -m file -a 'path=/tmp/test.txt state=touch'192.168.56.88 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "dest": "/tmp/test.txt", "gid": 0, "group": "root", "mode": "0644", "owner": "root", "size": 0, "state": "file", "uid": 0}

2.创建一个目录

[root@ansible ~]# ansible mysql -m file -a 'path=/tmp/test state=directory'192.168.56.88 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "gid": 0, "group": "root", "mode": "0755", "owner": "root", "path": "/tmp/test", "size": 6, "state": "directory", "uid": 0}

3.创建一个软连接文件

[root@ansible tmp]# ansible mysql -m file -a 'src=/tmp/test state=link path=/tmp-test-ln'192.168.56.88 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "dest": "/tmp-test-ln", "gid": 0, "group": "root", "mode": "0777", "owner": "root", "size": 9, "src": "/tmp/test", "state": "link", "uid": 0}

4.创建一个硬链接文件

[root@ansible tmp]# ansible mysql -m file -a 'src=/tmp/test state=hard path=/tmp-test-ln-hard'192.168.56.88 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "dest": "/tmp-test-ln-hard", "gid": 0, "group": "root", "mode": "0644", "owner": "root", "size": 0, "src": "/tmp/test", "state": "hard", "uid": 0}

5.创建一个文件,并设置权限,属主,属组​

[root@ansible tmp]# ansible mysql -m file -a 'state=touch path=/tmp/test mode=777 owner=mysql group=mysql'192.168.56.88 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "dest": "/tmp/test", "gid": 1000, "group": "mysql", "mode": "0777", "owner": "mysql", "size": 0, "state": "file", "uid": 1000}

6.修改一个文件得权限,属主,属组

[root@ansible tmp]# ansible mysql -m file -a 'path=/tmp/test mode=000'192.168.56.88 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "gid": 1000, "group": "mysql", "mode": "0000", "owner": "mysql", "path": "/tmp/test", "size": 0, "state": "file", "uid": 1000}[root@ansible tmp]# ansible mysql -m file -a 'path=/tmp/test owner=root'192.168.56.88 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "gid": 1000, "group": "mysql", "mode": "0000", "owner": "root", "path": "/tmp/test", "size": 0, "state": "file", "uid": 0}[root@ansible tmp]# ansible mysql -m file -a 'path=/tmp/test group=root'192.168.56.88 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "gid": 0, "group": "root", "mode": "0000", "owner": "root", "path": "/tmp/test", "size": 0, "state": "file", "uid": 0}

7.删除文件 / 目录

[root@ansible tmp]# ansible mysql -m file -a 'state=absent path=/tmp/test'192.168.56.88 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "path": "/tmp/test", "state": "absent"}

删除文件夹

[root@ansible tmp]# ansible mysql -m file -a 'state=absent path=/tmp/directory'192.168.56.88 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "path": "/tmp/directory", "state": "absent"}

ansible

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Docsify文档项目封装的微信小程序
下一篇:2019-nCoV 疫情患者同程查询小程序(云开发版)(2019-ncov属于乙类传染病,但按甲类传染病进行管理)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~