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"这一级的路径

相关推荐
UIUI3 分钟前
list_for_each_entry
linux·数据结构·链表
LeenixP29 分钟前
RK3576-Debian12删除userdata分区
linux·运维·服务器·数据库·debian·开发板
qq_ceiling31 分钟前
H3C交换机配置M-LAG
运维·服务器·网络
warton881 小时前
ubuntu24 安装 proxsql 实现数据库代理
linux·运维·mysql·ubuntu
会跑的葫芦怪1 小时前
cursor 打开wsl Ubuntu项目
linux·运维·ubuntu
用户467244544991 小时前
linux的网络配置
linux
Lueeee.2 小时前
字符设备驱动---自己实现点LED
linux
Full Stack Developme2 小时前
linux sudo su su - 三者区别
linux·运维·服务器
Byron Loong2 小时前
【系统】Linux内核和发行版的关系
linux·运维·服务器
weixin_399380692 小时前
OA 系统假死问题分析与优化
java·运维