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

相关推荐
杭州泽沃电子科技有限公司17 分钟前
告别翻山越岭!智能监拍远程守护输电线路安全
运维·人工智能·科技·安全
小韩博1 小时前
metasploit 框架安装更新遇到无法下载问题如何解决
linux·网络安全·公钥·下载失败
长臂人猿1 小时前
JVM常用工具:jstat、jmap、jstack
linux·运维·jvm
轻松Ai享生活2 小时前
揭秘 linux:一张图看懂系统配置的核心
linux
wdxylb2 小时前
云原生俱乐部-RH134知识点总结(2)
linux·云原生
_Chipen2 小时前
lazy_vim_cmake_clangd_从零到自动补全与语法检查
linux·编辑器·vim
椰子今天很可爱3 小时前
静态库和动态库
linux
檀越剑指大厂3 小时前
【Linux系列】如何在 Linux 服务器上快速获取公网
linux·服务器·php
共享家95273 小时前
linux-高级IO(上)
java·linux·服务器
HWL56795 小时前
“preinstall“: “npx only-allow pnpm“
运维·服务器·前端·javascript·vue.js