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

相关推荐
Magic--1 分钟前
Linux exec进程替换详解
linux·运维·服务器
道阻且长行则将至!2 分钟前
Linux 轻量级桌面环境
linux·运维·服务器·桌面管理器·ubuntu轻量级桌面
qqty12174 分钟前
Nginx反向代理出现502 Bad Gateway问题的解决方案
运维·nginx·gateway
YMWM_13 分钟前
服务器上的cursor同步本地插件
运维·服务器·chrome
Trouvaille ~14 分钟前
【项目篇】从零手写高并发服务器(十):性能测试与项目总结
linux·运维·c++·reactor·性能测试·高并发服务器·webbench
C++ 老炮儿的技术栈15 分钟前
Tcp客户端报错原因分析
linux·c语言·网络·c++·网络协议·tcp/ip
co_wait17 分钟前
【C语言】Linux系统文件操作函数基本使用
linux·c语言·microsoft
xiaomo224921 分钟前
javaee-网络原理(理论)
linux·服务器·网络
炘爚25 分钟前
Linux 进程管理 GCC/GDB 编译调试
linux·运维·服务器
不想好好取名字25 分钟前
Ubuntu apt启用dbg符号库
linux·运维·ubuntu