Ansible安装及模块管理

时间:2025-03-26 21:28:08
`路径opt下的文件,用户为test02,组指定为mysql,权限为666` [root@localhost ~]# ansible mysql -m file -a 'path=/opt/ owner=test02 group=mysql mode=666' 192.168.18.148 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "gid": 306, "group": "mysql", "mode": "0666", "owner": "test02", "path": "/opt/", "secontext": "system_u:object_r:usr_t:s0", "size": 12, "state": "file", "uid": 306 } `此时回到被管理端2:mysql中opt目录下的文件的详细情况` [root@localhost ~]# cd /opt/ [root@localhost opt]# ls -l 总用量 8 -rw-r--r--. 1 root root 595 2月 3 09:24 drwxr-xr-x. 2 root root 6 3月 26 2015 rh -rw-rw-rw-. 1 test02 mysql 12 2月 3 09:31 #此时文件属主为test02,属组为mysql,权限为666 `设置/opt/为/opt/的链接文件` [root@localhost ~]# ansible mysql -m file -a 'src=/opt/ path=/opt/ state=link' 192.168.18.148 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "dest": "/opt/", "gid": 0, "group": "root", "mode": "0777", "owner": "root", "secontext": "unconfined_u:object_r:usr_t:s0", "size": 13, "src": "/opt/", "state": "link", "uid": 0 } `此时回到被管理端2:mysql中opt目录下查看此链接文件` [root@localhost opt]# ls -l 总用量 8 -rw-r--r--. 1 root root 595 2月 3 09:24 drwxr-xr-x. 2 root root 6 3月 26 2015 rh -rw-rw-rw-. 1 test02 mysql 12 2月 3 09:31 lrwxrwxrwx. 1 root root 13 2月 3 09:59 -> /opt/ #链接性的文件 `创建一个空文件` [root@localhost ~]# ansible mysql -m file -a 'path=/opt/ state=touch' 192.168.18.148 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "dest": "/opt/", "gid": 0, "group": "root", "mode": "0644", "owner": "root", "secontext": "unconfined_u:object_r:usr_t:s0", "size": 0, "state": "file", "uid": 0 } `此时回到被管理端2:mysql中opt目录下文件的详细情况` [root@localhost opt]# ls #此时有文件 rh [root@localhost opt]# cat #因为是空文件,所以没有内容 `删除创建的空文件` [root@localhost ~]# ansible mysql -m file -a 'path=/opt/ state=absent' 192.168.18.148 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "path": "/opt/", "state": "absent" } `此时回到被管理端2:mysql中opt目录下是否有文件` [root@localhost opt]# ls rh