ansible 配置yum源

ansible配置yum源 有两种方式,一种是可以写好sh脚本,然后ansible去执行sh文件

另外一种就是使用yum_repository库

本文讲使用库的方式

本文使用的环境是centos7 ,配置也是按照7去配置的,没有写动态配置

直接上代码

bash 复制代码
[root@vm-2 ~]# cat yum.yml 
---
- hosts: testvm
  tasks:
    - name: yum centos7
      yum_repository:
        name: bash
        baseurl:  https://mirrors.aliyun.com/centos/7/os/x86_64/
        enabled: yes
        gpgcheck: no
        mode: 0644
        file: bash
        description: base
        state: present
    - name: yum epel
      yum_repository:
        name: epel
        baseurl: https://mirrors.aliyun.com/epel/7/x86_64/
        enabled: yes
        gpgcheck: no
        mode: 0644
        file: bash
        description: epel
        state: present

    - name: yum-clean-metadata
      command: yum clean all # | yum makecache fast | yum repolist
      args:
        warn: no

    - name: yum-make-fast
      command: yum makecache fast
      args:
        warn: no


    - name: yum-repolist
      command: yum repolist
      args:
        warn: no

执行效果

bash 复制代码
[root@192 yum.repos.d]# cat bash.repo 
[epel]
baseurl = https://mirrors.aliyun.com/epel/7/x86_64/ 
enabled = 1
gpgcheck = 0
name = epel

[bash]
baseurl = https://mirrors.aliyun.com/centos/7/os/x86_64/
enabled = 1
gpgcheck = 0
name = base

重点是url的配置,要找到"repodata"这一级的路径

相关推荐
CAFEBABE 3417 分钟前
linux离线安装docker并启动
linux·docker·eureka
wanhengidc1 小时前
云手机的存储空间可以灵活扩展吗?
运维·服务器·科技·智能手机·云计算
Danileaf_Guo1 小时前
256台H100服务器的RoCEv2无损与全互联算力网络建设方案
运维·服务器·网络
解压专家6662 小时前
怎么找书?怎么传输?在Kred里完成的全过程
运维·服务器·网络
OnlyEasyCode2 小时前
快速上手!查看、拷贝、编辑、远程连接Linux命令
linux·运维·服务器
dualven_in_csdn2 小时前
UDP广播接收小优化
linux·运维·服务器
Xの哲學3 小时前
Linux二层转发: 从数据包到网络之桥的深度解剖
linux·服务器·算法·架构·边缘计算
石像鬼₧魂石3 小时前
Termux ↔ Windows 靶机 反向连接实操命令清单
linux·windows·学习
yuguo.im3 小时前
Docker 两大基石:Namespace 和 Cgroups
运维·docker·容器
亮子AI3 小时前
application/json 服务器收到的是字符串,还是json对象?
运维·服务器·json