Ansible 更换aliyun 镜像 并下载tree

目录

这里安装一个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/' ``` ![在这里插入图片描述](https://file.jishuzhan.net/article/1761315445001949185/d9b9c7f196297e3140ac9cc702c7de98.webp) 可以看到已经下载到 aliyuan 的镜像了 清理缓存 ```sh ansible slave -m shell -a 'yum clean all' ``` ![在这里插入图片描述](https://file.jishuzhan.net/article/1761315445001949185/30a5a9055bd076a9cc21ca0c9ef5f847.webp) 生成缓存 ```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' ``` ![在这里插入图片描述](https://file.jishuzhan.net/article/1761315445001949185/2222efa2b32f90222a4280a9deea2aa2.webp) ### 更换成功 这里下载一个 tree 服务 ![在这里插入图片描述](https://file.jishuzhan.net/article/1761315445001949185/0e5f7e9de76c43992e6bb2305004b5ab.webp) ### 安装扩展源 ```sh ansible slave -m yum -a 'name=epel-release state=present' ``` 扩展源 安装成功 ![在这里插入图片描述](https://file.jishuzhan.net/article/1761315445001949185/6f26fe3abee6d957bdd4547aac198e9c.webp) ### 更换源之后 的三个命令 ```sh # 清理 yum clean all # 缓存源 信息 yum makecache # 查看源 yum repolist ``` *** ** * ** *** 补充完毕

相关推荐
扑火的小飞蛾3 天前
【Ansible学习笔记01】 批量执行 shell 命令
笔记·学习·ansible
oMcLin3 天前
如何在 Red Hat Linux 服务器上使用 Ansible 自动化部署并管理多节点 Hadoop 集群?
linux·服务器·ansible
linux修理工6 天前
vagrant ubuntu 22.04 ansible 配置
ubuntu·ansible·vagrant
biubiubiu07067 天前
Ansible自动化
运维·自动化·ansible
秋4277 天前
ansible配置与模块介绍
ansible
秋4278 天前
ansible剧本
linux·服务器·ansible
码农101号9 天前
Ansible - Role介绍 和 使用playbook部署wordPress
android·ansible
2301_8000509910 天前
Ansible
运维·ansible
阎*水12 天前
Ansible 核心要点总结
ansible
小安运维日记12 天前
RHCA - DO374 | Day09:自定义内容集和执行环境
linux·运维·服务器·系统架构·ansible·改行学it