Adding epel repo - baseurl apparantly not correct

I need the epel repos on a rhel9 target in order to get some packages

- name: Add epel repository
  ansible.builtin.yum_repository:
    name: epel
    description: EPEL YUM repo
  # baseurl: "https://download.fedoraproject.org/pub/epel/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}"
    baseurl: "https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm"
  become: true
  become_user: root
  notify: yum-clean-metadata

goes through, but the subsquent task installing some packages fails with i.e.

failed: [vm-414001-0433.step.zrz.dvz.cn-mv.de] (item=geos) => {"ansible_loop_var": "item", "changed": false, "item": "geos", "msg": "Failed to download metadata for repo 'epel': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried", "rc": 1, "results": []}

so I guess my base_url: line is not correct. Any hint how to formulate this?

If you want to configure the EPEL repository by installing the RPM file for it, then you should use ansible.builtin.dnf

- name: Add EPEL repository
  ansible.builtin.dnf:
    name: "https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm"
    state: present

If you want to configure the repository directly, then your baseurl should be the… base or root of the repository url.

- name: Add epel repository
  ansible.builtin.yum_repository:
    name: epel
    description: EPEL YUM repo
    baseurl: "https://dl.fedoraproject.org/pub/epel/{{ ansible_distribution_major_version }}/Everything/{{ ansible_architecture }}"
    gpgkey: "https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-{{ ansible_distribution_major_version }}"
  become: true
  become_user: root
  notify: yum-clean-metadata

EDIT: Ah, Denney got first. Here is my original answer:

Mmmmm, you are doing it wrong :slight_smile:. The base_url you have specified is not a base_url of the EPEL repo but an URL to the EPEL repo release RPM package. When doing the configuration manually, you install the EPEL repo by doing:

# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm

So the equivalent of this in Ansible would be:

- name: Add epel repository
  ansible.builtin.dnf:
    name: "https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm"
  become: true
  become_user: root
  notify: yum-clean-metadata
2 Likes