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

相关推荐
java叶新东老师3 小时前
git stash 命令详解
linux·运维·flink
写bug的羊羊4 小时前
CentOS 9 配置国内 YUM 源
linux·运维·centos
国科安芯5 小时前
抗辐照芯片在低轨卫星星座CAN总线通讯及供电系统的应用探讨
运维·网络·人工智能·单片机·自动化
gx23486 小时前
HCLP--MGER综合实验
运维·服务器·网络
angushine6 小时前
鲲鹏服务器部署Kafka2.8.1
运维·服务器
Johny_Zhao6 小时前
CentOS Stream 9上部署FTP应用服务的两种方法(传统安装和docker-compose)
linux·网络安全·信息安全·kubernetes·云计算·containerd·ftp·yum源·系统运维
一个网络学徒7 小时前
MGRE综合实验
运维·服务器·网络
守望时空337 小时前
RustDesk搭建指南
linux
C++ 老炮儿的技术栈7 小时前
在 Scintilla 中为 Squirrel 语言设置语法解析器的方法
linux·运维·c++·git·ubuntu·github·visual studio
白鹭8 小时前
基于LNMP架构的分布式个人博客搭建
linux·运维·服务器·网络·分布式·apache