state:installed 安装软件包
removed 卸载软件包
disable_gpg_check=yes :取消密钥的认证
update_cache=yes 更新缓存,需要在指定安装包时使用
1.确定被控端的yum本地源或者网络源
2.安装一个httpd yum源
[root@ansible ~]# ansible mysql -m yum -a 'name=gcc state=installed'
192.168.56.88 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"msg": "",
"rc": 0,
"results": [
"gcc-4.8.5-44.el7.x86_64 providing gcc is already installed"
]
}
[root@ansible ~]# ansible mysql -m yum -a 'name=g++ state=installed'
192.168.56.88 | FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"msg": "No package matching 'g++' found available, installed or updated",
"rc": 126,
"results": [
"No package matching 'g++' found available, installed or updated"
]
}
[root@ansible ~]# ansible mysql -m yum -a 'name=gcc state=installed'
192.168.56.88 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"changes": {
"installed": [
"gcc"
]
},
"msg": "Warning: RPMDB altered outside of yum./n",
"rc": 0,
"results": [
"Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-/n : manager/n/nThis system is not registered with an entitlement server. You can use subscription-manager to register./n/nResolving Dependencies/n--> Running transaction check/n---> Package gcc.x86_64 0:4.8.5-44.el7 will be installed/n--> Finished Dependency Resolution/n/nDependencies Resolved/n/n================================================================================/n Package Arch Version Repository Size/n================================================================================/nInstalling:/n gcc x86_64 4.8.5-44.el7 rhel7 16 M/n/nTransaction Summary/n================================================================================/nInstall 1 Package/n/nTotal download size: 16 M/nInstalled size: 37 M/nDownloading packages:/nRunning transaction check/nRunning transaction test/nTransaction test succeeded/nRunning transaction/n Installing : gcc-4.8.5-44.el7.x86_64 1/1 /n Verifying : gcc-4.8.5-44.el7.x86_64 1/1 /n/nInstalled:/n gcc.x86_64 0:4.8.5-44.el7 /n/nComplete!/n"
]
}
3.安装独立的rpm包
[root@ansible ~]# ansible mysql -m yum -a 'name=/home/compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm'
192.168.56.88 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"changes": {
"installed": [
"/home/compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm"
]
},
"msg": "",
"rc": 0,
"results": [
"Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-/n : manager/n/nThis system is not registered with an entitlement server. You can use subscription-manager to register./n/nExamining /home/compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm: compat-libstdc++-33-3.2.3-72.el7.x86_64/nMarking /home/compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm to be installed/nResolving Dependencies/n--> Running transaction check/n---> Package compat-libstdc++-33.x86_64 0:3.2.3-72.el7 will be installed/n--> Finished Dependency Resolution/n/nDependencies Resolved/n/n================================================================================/n Package Arch Version Repository Size/n================================================================================/nInstalling:/n compat-libstdc++-33/n x86_64 3.2.3-72.el7 /compat-libstdc++-33-3.2.3-72.el7.x86_64 811 k/n/nTransaction Summary/n================================================================================/nInstall 1 Package/n/nTotal size: 811 k/nInstalled size: 811 k/nDownloading packages:/nRunning transaction check/nRunning transaction test/nTransaction test succeeded/nRunning transaction/n Installing : compat-libstdc++-33-3.2.3-72.el7.x86_64 1/1 /n Verifying : compat-libstdc++-33-3.2.3-72.el7.x86_64 1/1 /n/nInstalled:/n compat-libstdc++-33.x86_64 0:3.2.3-72.el7 /n/nComplete!/n"
]
}
[root@ansible ~]# ansible mysql -m yum -a 'name=/home/compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm'
192.168.56.88 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"msg": "",
"rc": 0,
"results": [
"compat-libstdc++-33-3.2.3-72.el7.x86_64 providing /home/compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm is already installed"
]
4.安装gcc并清除缓存
[root@ansible ~]# ansible mysql -m yum -a 'name=gcc update_cache=yes'
192.168.56.88 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"changes": {
"installed": [
"gcc"
]
},
"msg": "Warning: RPMDB altered outside of yum./n",
"rc": 0,
"results": [
"Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-/n : manager/n/nThis system is not registered with an entitlement server. You can use subscription-manager to register./n/nResolving Dependencies/n--> Running transaction check/n---> Package gcc.x86_64 0:4.8.5-44.el7 will be installed/n--> Finished Dependency Resolution/n/nDependencies Resolved/n/n================================================================================/n Package Arch Version Repository Size/n================================================================================/nInstalling:/n gcc x86_64 4.8.5-44.el7 rhel7 16 M/n/nTransaction Summary/n================================================================================/nInstall 1 Package/n/nTotal download size: 16 M/nInstalled size: 37 M/nDownloading packages:/nRunning transaction check/nRunning transaction test/nTransaction test succeeded/nRunning transaction/n Installing : gcc-4.8.5-44.el7.x86_64 1/1 /n Verifying : gcc-4.8.5-44.el7.x86_64 1/1 /n/nInstalled:/n gcc.x86_64 0:4.8.5-44.el7 /n/nComplete!/n"
]
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
ansible