ysql:/sbin/nologin
//删除受控机上的mysql用户
[root@ansible ~]# ansible 192.168.118.130 -m user -a 'name=mysql state=absent'
192.168.118.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"force": false,
"name": "mysql",
"remove": false,
"state": "absent"
}
[root@ansible ~]# ansible 192.168.118.130 -a 'grep mysql /etc/passwd'
192.168.118.130 | FAILED | rc=1 >>
non-zero return code
ansible常用模块之yum
yum模块用于在指定节点机器上通过yum管理软件,其支持的参数主要有两个
state常用的值:
- latest:安装软件
- installed:安装软件
- present:安装软件
- removed:卸载软件
- absent:卸载软件
若想使用yum来管理软件,请确保受控机上的yum源无异常。
//在受控机上查询看httpd软件是否安装
[root@localhost ~]# rpm -qa|grep httpd
[root@localhost ~]#
//在ansible主机上使用yum模块在受控机上安装httpd
[root@ansible ~]# ansible 192.168.118.130 -m yum -a 'name=httpd state=present'
192.168.118.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Installed: httpd-tools-2.4.37-47.module_el8.6.0+1111+ce6f4ceb.1.x86_64",
"Installed: apr-1.6.3-12.el8.x86_64",
"Installed: mailcap-2.1.48-3.el8.noarch",
"Installed: mod_http2-1.15.7-5.module_el8.6.0+1111+ce6f4ceb.x86_64",
"Installed: apr-util-1.6.1-6.el8.x86_64",
"Installed: httpd-2.4.37-47.module_el8.6.0+1111+ce6f4ceb.1.x86_64",
"Installed: apr-util-bdb-1.6.1-6.el8.x86_64",
"Installed: apr-util-openssl-1.6.1-6.el8.x86_64",
"Installed: httpd-filesystem-2.4.37-47.module_el8.6.0+1111+ce6f4ceb.1.noarch",
"Installed: centos-logos-httpd-85.8-2.el8.noarch"
]
}
//查看受控机上是否安装了httpd
[root@localhost ~]# rpm -qa|grep httpd
httpd-2.4.37-47.module_el8.6.0+1111+ce6f4ceb.1.x86_64
httpd-tools-2.4.37-47.module_el8.6.0+1111+ce6f4ceb.1.x86_64
httpd-filesystem-2.4.37-47.module_el8.6.0+1111+ce6f4ceb.1.noarch
centos-logos-httpd-85.8-2.el8.noarch
//在ansible主机上使用yum模块在受控机上卸载httpd
[root@ansible ~]# ansible 192.168.118.130 -m yum -a 'name=httpd state=absent'
192.168.118.130 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Removed: mod_http2-1.15.7-5.module_el8.6.0+1111+ce6f4ceb.x86_64",
"Removed: httpd-2.4.37-47.module_el8.6.0+1111+ce6f4ceb.1.x86_64"
]
}
//查看受控机上是否安装了httpd,httpd的包已经被卸载了,只剩依赖包了
[root@localhost ~]# rpm -qa|grep httpd
httpd-tools-2.4.37-47.module_el8.6.0+1111+ce6f4ceb.1.x86_64
httpd-filesystem-2.4.37-47.module_el8.6.0+1111+ce6f4ceb.1.noarch
centos-logos-httpd-85.8-2.el8.noarch
ansible常用模块之service
service模块用于管理受控机上的服务。
//查看受控主机上httpd服务是否开启,这里显示未开启
[root@localhost ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; ve