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

相关推荐
Nerd Nirvana1 小时前
软考—系统架构设计(案例 | 论文)
linux·系统架构·软件工程·软考·计算机基础
勤奋的凯尔森同学2 小时前
webmin配置终端显示样式,模仿UbuntuDesktop终端
linux·运维·服务器·ubuntu·webmin
技术小齐6 小时前
网络运维学习笔记 016网工初级(HCIA-Datacom与CCNA-EI)PPP点对点协议和PPPoE以太网上的点对点协议(此处只讲华为)
运维·网络·学习
ITPUB-微风6 小时前
Service Mesh在爱奇艺的落地实践:架构、运维与扩展
运维·架构·service_mesh
打不了嗝 ᥬ᭄6 小时前
Linux的权限
linux
落幕6 小时前
C语言-进程
linux·运维·服务器
深度Linux7 小时前
C++程序员内功修炼——Linux C/C++编程技术汇总
linux·项目实战·c/c++
chenbin5207 小时前
Jenkins 自动构建Job
运维·jenkins
java 凯7 小时前
Jenkins插件管理切换国内源地址
运维·jenkins
AI服务老曹7 小时前
运用先进的智能算法和优化模型,进行科学合理调度的智慧园区开源了
运维·人工智能·安全·开源·音视频