ansible 配置yum源

ansible配置yum源 有两种方式,一种是可以写好sh脚本,然后ansible去执行sh文件

另外一种就是使用yum_repository库

本文讲使用库的方式

本文使用的环境是centos7 ,配置也是按照7去配置的,没有写动态配置

直接上代码

[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

执行效果

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值