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

相关推荐
扬帆破浪几秒前
免费开源AI软件.桌面单机版,可移动的AI知识库,察元 AI桌面版:本地离线知识库的最小依赖 Linux下不联外网装包跑通
linux·运维·人工智能
kyle~2 分钟前
Linux---挂载系统
linux·运维·服务器
qinyia3 分钟前
服务器异常流量排查:发现并清除kswpad挖矿后门及持久化守护进程
运维·服务器·人工智能
凡梦千华10 分钟前
CentOS系统安装Elasticsearch,RPM包方式
linux·elasticsearch·centos
倔强的石头10611 分钟前
【Linux 指南】文件系统系列(二):核心抽象层 —— 块 、分区 、inode 从原理到实操
linux·服务器·数据库
谷雨不太卷12 分钟前
TCP外壳
linux·网络·tcp/ip
曾庆睿15 分钟前
【基于 RHEL 9.3 的 K8s + GitLab 全自动化部署环境搭建第三篇】
运维
sanguine_boy16 分钟前
csv、log、txt文件过大,需要拆分成多个文件
linux
日取其半万世不竭21 分钟前
Mattermost 自建团队协作平台:开源的 Slack 替代品
运维
HalvmånEver22 分钟前
MySQL 使用 C 语言连接
linux·数据库·学习·mysql