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/'

可以看到已经下载到 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

补充完毕

相关推荐
Hy行者勇哥4 天前
用Cursor智能编写Ansible/Terraform脚本,打通CI/CD链路
ci/cd·ansible·terraform
芷栀夏6 天前
飞牛NAS怎么部署Immich?家庭照片自动备份与远程访问教程
服务器·nginx·ansible
悠然南风17 天前
Ansible常见模块总结及LDAP Role 编写与调试
ansible
祺风挽楠1 个月前
ansible编辑
网络·ansible
芳心粽伙饭1 个月前
Ansible课后作业
ansible
烁3471 个月前
Ansible初识
ansible
烁3471 个月前
Ansible安装部署调试
ansible
烁3471 个月前
Ansible命令
ansible
小义_1 个月前
【Ansible】(三)基础配置与连接设置
云原生·ansible
炸炸鱼.1 个月前
Ansible 企业级实战:Playbook 与 Roles 完全指南
网络·ansible