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

相关推荐
默|笙1 分钟前
【Linux】线程同步与互斥_日志与线程池
android·linux·运维
一条咸鱼¥¥¥4 分钟前
【运维笔记】华为防火墙远程接入用户开通与禁用方法
运维·网络·华为·远程用户
Asurplus6 分钟前
【Ngrok】Linux运行内网穿透工具Ngrok
linux·运维·服务器·内网穿透·ngrok
ancktion13 分钟前
ubuntu多gcc版本切换
linux·运维·ubuntu
热爱Liunx的丘丘人15 分钟前
21.内核和内核参数
linux·运维·服务器
乐大师18 分钟前
passwd修改密码提示“passwd:Moudle is unknown”
linux·修改密码报错·passwd命令报错
wanhengidc19 分钟前
物理服务器的功能都有哪些
运维·服务器·网络·安全·web安全·智能手机
东北甜妹19 分钟前
Docker 基础
linux·docker·开源
papaofdoudou33 分钟前
AMD-V 嵌套分页白皮书翻译
java·linux·服务器
篱笆院的狗37 分钟前
未备案域名申请SSL证书
linux