共计 1476 个字符,预计需要花费 4 分钟才能阅读完成。
一、yum 模块
yum 模块用于使用 yum 命令来实现软件包的安装与卸载。
https://docs.ansible.com/ansible/latest/modules/yum_module.html#yum-module
参数 | 说明 |
---|---|
name | 需要安装软件包的名称 |
list= installed, updates, available and repos | 列出已安装 需要更新 可获得的 和 yum 源 |
state= absent removed installed present latest | 删除、删除、安装确认、安装确认、安装最新版本 |
list: 列出包信息
[root@manage01 ~]# ansible -m yum group1 -a "list=repos"
192.168.98.201 | FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"msg": "同步仓库'dvd'缓存失败",
"rc": 1,
"results": []}
原因就是源不好用,这里是 cdrom 没有挂载光盘
使用 yum 安装一个软件(前提:group1 的机器上的 yum 配置都已经 OK)
[root@manage01 ~]# ansible -m yum group1 -a "name=vsftpd"
192.168.98.203 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "",
"rc": 0,
"results": ["Installed: vsftpd",
"Installed: vsftpd-3.0.3-28.el8.x86_64"
]
}
192.168.98.202 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "",
"rc": 0,
"results": ["Installed: vsftpd",
"Installed: vsftpd-3.0.3-28.el8.x86_64"
]
}
192.168.98.201 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "",
"rc": 0,
"results": ["Installed: vsftpd",
"Installed: vsftpd-3.0.3-28.el8.x86_64"
]
}
删除软件包
[root@manage01 ~]# ansible -m yum 192.168.98.201 -a "state=absent name=vsftpd"
192.168.98.201 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "",
"rc": 0,
"results": ["Removed: vsftpd-3.0.3-28.el8.x86_64"
]
}
二、学习视频
正文完
星哥玩云-微信公众号