How to disable all repositories using yum module in ansible?

12,136

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
Share:
12,136
JPNagarajan
Author by

JPNagarajan

Updated on June 26, 2022

Comments

  • JPNagarajan
    JPNagarajan almost 2 years

    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
    
    • error404
      error404 about 5 years
      what was the outcome of the trial? Any error ?
    • JPNagarajan
      JPNagarajan about 5 years
      Didn't got any error.But just want to know whether this is correct way to disable all repos?
    • error404
      error404 about 5 years
      Ohk..the list way was easily there in ansible docs to refer. But your question was to delete all the repos using wild card which is not supported may be you can apply some logic and generate the list dynamically and pass it the yum module