每日学习-ansible yum_repository模块

yum_repository模块用于在基于RPM的Linux发行版中添加或删除YUM仓库。

yum_repository模块常用参数

name:必须参数,指定唯一的仓库ID,state为present或absent时需要设置name参数
baseurl:指定yum仓库repodata目录的URL,可以是多个,如果设置为多个,需要使用"metalink"和"mirrorlist"参数
enabled:使用此yum仓库
gpgcheck:是否对软件包执行gpg签名检查
gpgkey:gpg秘钥的URL
mode:权限设置,当设置为preserve时,文件将与源文件权限相同
file:用于设置仓库的配置文件名称,即设置”.repo”配置文件的文件名前缀,在不使用此参数的情况下,默认以 name 参数的仓库ID作为”.repo”配置文件的文件名前缀,同一个”.repo” 配置文件中可以存在多个 yum 源
state:状态,默认的present为安装此yum仓库,absent为删除此yum仓库
description:设置仓库的注释信息
async:如果yum仓库支持并行,yum将并行下载软件包和元数据
bandwidth:与throttle参数一起使用,限制yum可用的网络带宽

yum_repository模块示例
安装yum仓库

  - name: install yum repo 
    yum_repository:
      name: rh294_BASE
      state: present
      description: RHCE8.0 test
      baseurl: http://content.example.com/rhel8.0/x86_64/dvd/BaseOS
      gpgcheck: yes
      gpgkey: http://content.example.com/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-releas
      enabled: yes

卸载yum仓库

  tasks:
  - name: uninstall yum repo
    yum_repository:
      name: rh294_BASE
      state: absent
    notify: yum-clean-metadata
  handlers:
    - name: clean yum cache
      shell: yum clean metadata 

参考:ansible-doc yum_repository

猜你喜欢

转载自blog.51cto.com/jiayimeng/2587601