ansible通过yum/dnf模块给受控机安装软件(ansible2.9.5)
一,使用yum/dnf模块要注意的地方:
使用dnf软件安装/卸载时,需要有root权限,
所以要使用become参数
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱:
二,用yum模块卸载软件
#name:软件的名字
#state: 状态,取值有:present:默认的,表示为安装
lastest: 安装为最新的版本
absent:表示删除
[ ~]$ ansible yujian -m yum -a ‘name=screen state=absent‘ --become --become-method=sudo --become-user=root 121.122.123.47 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": true, "msg": "", "rc": 0, "results": [ "Removed: screen-4.6.2-10.el8.x86_64" ] }
三,用yum模块安装软件:
[ ~]$ ansible yujian -m yum -a ‘name=screen‘ --become --become-method=sudo --become-user=root 121.122.123.47 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": true, "msg": "", "rc": 0, "results": [ "Installed: screen-4.6.2-10.el8.x86_64" ] }
四,安装软件时关闭gpg验证
#disable_gpg_check 值为yes时,禁用gpg验证
[ ~]$ ansible yujian -m yum -a ‘name=screen disable_gpg_check=yes‘ --become --become-method=sudo --become-user=root
说明:如果对应的 yum 源没有开启 gpg 验证,则需要将此参数的值设置为 yes,否则会报错而无法进行安装
因为这里要和server交互
五,安装软件时指定来源库
#enablerepo 指定安装时的来源repo
[ ~]$ ansible yujian -m yum -a ‘name=screen enablerepo=epel‘ --become --become-method=sudo --become-user=root
六,查看centos的版本:
[ ~]$ cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core)
相关推荐
laisean 2020-09-27
onepiecedn 2020-10-29
guchengxinfen 2020-10-12
houdaiye 2020-09-23
逆时针 2020-08-19
pzczyy 2020-08-19
annan 2020-08-02
hpujsj 2020-07-26
annan 2020-07-18
逆时针 2020-06-21
annan 2020-06-20
逆时针 2020-06-14
逆时针 2020-06-14
awoyaoc 2020-06-12
逆时针 2020-06-09
piaotiejun 2020-06-07
awoyaoc 2020-06-07