一,使用yum/dnf模塊要注意的地方:
使用dnf軟件安裝/卸載時,需要有root權限,
所以要使用become參數
說明:劉宏締的架構森林是一個專注架構的博客,地址:https://www.cnblogs.com/architectforest
對應的源碼可以訪問這里獲取: https://github.com/liuhongdi/
說明:作者:劉宏締 郵箱: 371125307@qq.com
二,用yum模塊卸載軟件
#name:軟件的名字
#state: 狀態,取值有:present:默認的,表示為安裝
lastest: 安裝為最新的版本
absent:表示刪除
[liuhongdi@centos8 ~]$ 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模塊安裝軟件:
[liuhongdi@centos8 ~]$ 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驗證
[liuhongdi@centos8 ~]$ ansible yujian -m yum -a 'name=screen disable_gpg_check=yes' --become --become-method=sudo --become-user=root
說明:如果對應的 yum 源沒有開啟 gpg 驗證,則需要將此參數的值設置為 yes,否則會報錯而無法進行安裝
因為這里要和server交互
五,安裝軟件時指定來源庫
#enablerepo 指定安裝時的來源repo
[liuhongdi@centos8 ~]$ ansible yujian -m yum -a 'name=screen enablerepo=epel' --become --become-method=sudo --become-user=root
六,查看centos的版本:
[liuhongdi@centos8 ~]$ cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core)