# Adding epel repo - baseurl apparantly not correct

**URL:** <https://forum.ansible.com/t/adding-epel-repo-baseurl-apparantly-not-correct/38918>\
**Category:** Get Help\
**Created:** [December 5, 2024, 2:27pm UTC](https://forum.ansible.com/t/adding-epel-repo-baseurl-apparantly-not-correct/38918 "2024-12-05T14:27:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [December 5, 2024, 2:27pm UTC](https://forum.ansible.com/t/adding-epel-repo-baseurl-apparantly-not-correct/38918/1 "2024-12-05T14:27:46Z")

</div>

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

```yaml
- 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.

```auto
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?

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [December 5, 2024, 2:56pm UTC](https://forum.ansible.com/t/adding-epel-repo-baseurl-apparantly-not-correct/38918/2 "2024-12-05T14:56:50Z")

</div>

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

```yaml
- 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.

```auto
- 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

```

---

<div class="post-metadata">

**Author:** ![bvitnik](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bvitnik/32/4132_2.png) [@bvitnik](https://forum.ansible.com/u/bvitnik)\
**Post date:** [December 5, 2024, 3:00pm UTC](https://forum.ansible.com/t/adding-epel-repo-baseurl-apparantly-not-correct/38918/3 "2024-12-05T15:00:04Z")

</div>

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

Mmmmm, you are doing it wrong 🙂. 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:

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

```

So the equivalent of this in Ansible would be:

```auto
- 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

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [January 4, 2025, 3:00pm UTC](https://forum.ansible.com/t/adding-epel-repo-baseurl-apparantly-not-correct/38918/4 "2025-01-04T15:00:27Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
