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

相关推荐
大鹅同志28 分钟前
在服务器上开Juypter Lab教程(远程访问)
运维·服务器·pytorch·jupyter·cuda·云服务器
ID_14 HuFei43 分钟前
sed编辑器与awk的用法
linux·编辑器
文牧之1 小时前
PostgreSQL的walsender和walreceiver进程介绍
运维·数据库·postgresql
驯龙高手_追风1 小时前
Ubuntu下安装最新版本Apache2文件服务器
linux·服务器·ubuntu
炸裂狸花猫1 小时前
Linux技术04-IPVS
linux·运维·服务器
快快小毛毛1 小时前
CC攻击防御策略要怎么调整?使用游戏盾有效解决
运维·服务器·网络·tcp/ip·游戏·udp
ʚɞ4962 小时前
k8s环境下的相关操作
运维·excel
J老熊2 小时前
Linux下抓包分析Java应用程序HTTP接口调用:基于tcpdump与Wireshark的综合示例
java·linux·运维·web安全·http·面试
HoweWWW2 小时前
k8s中的存储
linux·容器·kubernetes
我叫啥都行3 小时前
计算机基础知识复习9.13
linux·笔记·后端·系统架构