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

相关推荐
赵文宇(温玉)2 小时前
Docker离线安装
运维·docker·容器
进击的荆棘2 小时前
Linux网络——传输层协议UDP
linux·运维·服务器·网络·udp
Android系统攻城狮3 小时前
FFmpeg深度解析之av_bsf_get_by_name:如何查找码流过滤器?(七十九)
linux·运维·ffmpeg·音视频进阶·ffmpeg音视频
Decay__4 小时前
PostgreSQL 监控体系构建 —— postgres_exporter + Prometheus + Grafana 全栈实战
运维·数据库·sql·postgresql
ShineWinsu5 小时前
对于Qt:TCP的解析
linux·c++·qt·网络协议·面试·tcp·客户端
Decay__6 小时前
PostgreSQL 告警与自动化运维 —— 告警分级收敛、Webhook、定时巡检、脚本库
运维·数据库·sql·postgresql
笔记本note6 小时前
Linux GPIO 技术详解
linux·gpio
东坡大表哥7 小时前
【Ubuntu】Ubuntu 20.04 LTS → 22.04 LTS 升级实录
android·linux·ubuntu
程序员agions7 小时前
Docker Compose 生产环境配置记录
运维·docker·容器
郝学胜-神的一滴7 小时前
Effective Python 条款45:巧用属性注解平滑升级类属性
运维·开发语言·数据库·python·网络协议·numpy