Friday, November 12, 2021

[SOLVED] How to disable all repositories using yum module in ansible?

Issue

I'm trying to disable all the yum repos and enable just 1 repo for installing a yum package.How to disable all repos using yum module?

Tried to use disablerepo='*' but not sure whether this is the correct method

- name: Update the uek kernel pkg on gateways
    yum:
      name: "{{ packages }}"
      disablerepo: "*"
      enablerepo: test_iso
    vars:
      packages:
      - kernel-uek
    become_user: root

Solution

The Ansible documentation suggests you must supply a comma-separated list of repo ids.

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

The example from the documentation:

- name: Install package with multiple repos disabled
  yum:
    name: sos
    disablerepo: "epel,ol7_latest"

You might look into using the yum_repository module as an alternative as well:

# 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


Answered By - Nick