如何在 ansible 中使用 yum 模块禁用所有存储库?
How to disable all repositories using yum module in ansible?
我正在尝试禁用所有 yum 存储库并仅启用 1 个存储库来安装 yum package.How 以禁用所有使用 yum 模块的存储库?
尝试使用 disablerepo='*' 但不确定这是否是正确的方法
- name: Update the uek kernel pkg on gateways
yum:
name: "{{ packages }}"
disablerepo: "*"
enablerepo: test_iso
vars:
packages:
- kernel-uek
become_user: root
Ansible documentation 建议您必须提供以逗号分隔的 repo id 列表。
disablerepo: Repoid of repositories to disable for the install/update operation. These repos will not persist beyond the transaction. When specifying multiple repos, separate them with a ",".
As of Ansible 2.7, this can alternatively be a list instead of "," separated string
文档中的示例:
- name: Install package with multiple repos disabled
yum:
name: sos
disablerepo: "epel,ol7_latest"
您也可以考虑使用 yum_repository 模块作为替代:
# Example removing a repository and cleaning up metadata cache
- name: Remove repository (and clean up left-over metadata)
yum_repository:
name: epel
state: absent
notify: yum-clean-metadata
正如 Nick 所指出的,当前的 yum 模块要求我们提供特定存储库名称的列表。
我们可以使用yum -q repolist
查询和解析存储库列表。
---
- hosts: localhost
tasks:
- name: Get list of yum repos (to disable them temporarily)
ansible.builtin.command: yum -q repolist
register: _yum_repolist_output
changed_when: False
- name: Install Docker RPMs
yum:
name: "http://mirror.centos.org/centos/7/os/x86_64/Packages/vim-enhanced-7.4.629-7.el7.x86_64.rpm"
enablerepo: []
disablerepo: "{{ _yum_repolist_output.stdout_lines[1:] | map('split',' ') | map('first') | list }}"
这不是一个理想的解决方案,但它似乎是在存储库配置损坏的设置中使用 yum
模块的唯一解决方案,例如在 air-gap 个系统上。
我正在尝试禁用所有 yum 存储库并仅启用 1 个存储库来安装 yum package.How 以禁用所有使用 yum 模块的存储库?
尝试使用 disablerepo='*' 但不确定这是否是正确的方法
- name: Update the uek kernel pkg on gateways
yum:
name: "{{ packages }}"
disablerepo: "*"
enablerepo: test_iso
vars:
packages:
- kernel-uek
become_user: root
Ansible documentation 建议您必须提供以逗号分隔的 repo id 列表。
disablerepo: Repoid of repositories to disable for the install/update operation. These repos will not persist beyond the transaction. When specifying multiple repos, separate them with a ",". As of Ansible 2.7, this can alternatively be a list instead of "," separated string
文档中的示例:
- name: Install package with multiple repos disabled
yum:
name: sos
disablerepo: "epel,ol7_latest"
您也可以考虑使用 yum_repository 模块作为替代:
# Example removing a repository and cleaning up metadata cache
- name: Remove repository (and clean up left-over metadata)
yum_repository:
name: epel
state: absent
notify: yum-clean-metadata
正如 Nick 所指出的,当前的 yum 模块要求我们提供特定存储库名称的列表。
我们可以使用yum -q repolist
查询和解析存储库列表。
---
- hosts: localhost
tasks:
- name: Get list of yum repos (to disable them temporarily)
ansible.builtin.command: yum -q repolist
register: _yum_repolist_output
changed_when: False
- name: Install Docker RPMs
yum:
name: "http://mirror.centos.org/centos/7/os/x86_64/Packages/vim-enhanced-7.4.629-7.el7.x86_64.rpm"
enablerepo: []
disablerepo: "{{ _yum_repolist_output.stdout_lines[1:] | map('split',' ') | map('first') | list }}"
这不是一个理想的解决方案,但它似乎是在存储库配置损坏的设置中使用 yum
模块的唯一解决方案,例如在 air-gap 个系统上。