目录
这里安装一个aliyun 的镜像
本案例 仅供实验参考 生产环境中请谨慎使用
查看系统版本
先查看linux 的系统 版本
sh
ansible slave -m shell -a 'uname -a'

找到对应 的版本
aliyun 链接:aliyun.com

找到对应版本
对当前镜像进行备份
nim
ansible slave -m shell -a ' mkdir /etc/yum.repos.d/yuan.bak && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/yuan.bak '
已经对原有的源备份成功
这里也是检查一下备份 可以看到已经移除了
sh
ansible slave -m shell -a 'ls /etc/yum.repos.d/'

可以看到已经移动到 yuan.bak 文件下边
下载aliyuan
nim
ansible slave -m shell -a ' wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo'

这里提醒我 可以使用get_url 模块 但是我使用 命令习惯了
警告\]:请考虑使用get_url或uri模块,而不是运行"wget"。如果需要 使用命令,因为get_url或uri不足,您可以将"warn:false"添加到此命令任务 或者在ansible.cfg中设置"command_warnings=False"以消除此消息。 检查下载 ```sh ansible slave -m shell -a 'ls /etc/yum.repos.d/' ```  可以看到已经下载到 aliyuan 的镜像了 清理缓存 ```sh ansible slave -m shell -a 'yum clean all' ```  生成缓存 ```sh ansible slave -m shell -a 'sed -i -e "/mirrors.cloud.aliyuncs.com/d" -e "/mirrors.aliyuncs.com/d" /etc/yum.repos.d/CentOS-Base.repo' ``` 查看当前yum 源 ```sh ansible slave -m shell -a 'yum repolist' ```  ### 更换成功 这里下载一个 tree 服务  ### 安装扩展源 ```sh ansible slave -m yum -a 'name=epel-release state=present' ``` 扩展源 安装成功  ### 更换源之后 的三个命令 ```sh # 清理 yum clean all # 缓存源 信息 yum makecache # 查看源 yum repolist ``` *** ** * ** *** 补充完毕