annan 2020-04-22
使用dnf软件安装/卸载时,需要有root权限,
所以要使用become参数
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱:
#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" ] }
[ ~]$ 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" ] }
#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
[ ~]$ cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core)