Ansible笔记——yum模块操作练习
主机配置 :
echo -e "[group1]\n192.168.18.100\n192.168.18.101" >> /etc/ansible/hosts
操作示例:
示例一、安装当前最新的Apache软件,如果存在则更新
ansible group1 -m yum -a "name=httpd state=latest" -i hosts
示例二、使用epel仓库安装
ansible group1 -m yum -a "name=httpd state=latest enablerepo=epel" -i hosts
示例三、更新所有软件包,但拍出和kernel,foo相关的
ansible group1 -m yum -a "name=* state=latest exclude=kernel*,foo*" -i hosts
示例四、删除Apache软件
ansible group1 -m yum -a "name=httpd state=absent"
----------------------------------------------------------------------------------------------------------
“示例一”执行过程中报错如下:
192.168.18.100 | FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"msg": "No package matching 'httpd' found available, installed or updated",
"rc": 126,
"results": [
"No package matching 'httpd' found available, installed or updated"
]
}
192.168.18.100主机安装apache失败,远程该主机尝试本地完成安装
仍然提示:“No package Apache available ”
原因:出现这种问题的原因是要安装的软件包默认不在centos的光盘yum仓库中,因此我们需要配置 epel仓库
解决方法:配置阿里云yum源,安装epel-release
1、配置阿里云网源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
2、配置epel源
yum install -y epel-release
(注意:以上修复操作也可从控制端使用command、yum完成)
结果:修复完成后,执行后续示例均能正常执行。

浙公网安备 33010602011771号