设为首页 加入收藏

TOP

ansible常用模块的介绍与使用(五)
2023-07-23 13:38:52 】 浏览:161
Tags:ansible 常用模
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管理软件,其支持的参数主要有两个

  • name:要管理的包名
  • state:要进行的操作

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
首页 上一页 2 3 4 5 6 7 8 下一页 尾页 5/9/9
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Ansible部署LNMP 下一篇海思3516系列芯片SPI速率慢问题深..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目