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

相关推荐
Jewel Q13 分钟前
PowerShell 和 CMD
运维
喜欢吃燃面17 分钟前
Linux:make自动化和实战演练
linux·学习
Mr_Xuhhh17 分钟前
GUI自动化测试--自动化简单示例
运维·服务器·自动化
羑悻的小杀马特23 分钟前
零成本自建私人知识库教学,Leanote+Cpolar 内网穿透,手机电脑随时同步,无需云服务器,效率翻倍!
运维·服务器·coplar·leanote
顾安r1 小时前
11.8 脚本网页 推箱子
linux·前端·javascript·flask
___波子 Pro Max.1 小时前
Linux source命令详解与应用场景
linux
橘子132 小时前
Linux网络基础(一)
linux·网络·arm开发
你想考研啊4 小时前
linux安装jdk和tomcat和并自启动
java·linux·tomcat
chevysky.cn5 小时前
Jenkins自动部署CI/CD
运维·ci/cd·jenkins
习惯就好zz6 小时前
WSL2 安装Ubuntu卡在安装进度0%无响应问题解决
linux·windows·ubuntu·wsl·wsl2