Tuesday, April 12, 2022

[SOLVED] Ansible install yum repo from rpm package

Issue

I'm trying to install a rpm package with Ansible. However, I can't figure it out how to do it correctly. I hope someone can help me up with this.

This is what I've done so far:

1. Using yum_repository module (Try 1)

    - name: "Setting up percona repository"
      yum_repository:
        name: "Percona"
        description: "Percona yum repository"
        baseurl: "http://www.percona.com/downloads/percona-release/redhat/latest/percona-release-0.1-4.noarch.rpm"

    - name: "Installing PMM client package"
      yum: pkg={{item}} state=installed
      with_items:
      - pmm-client

Result

    TASK [pmmhosts : Setting up percona repository] **********************************************************************
    changed: [server1]
    changed: [server2]

    TASK [pmmhosts : Installing PMM client package] **********************************************************************
    failed: [server1] (item=[u'pmm-client']) => {"changed": false, "item": ["pmm-client"], "msg": "Failure talking to yum: failure: repodata/repomd.xml from Percona: [Errno 256] No more mirrors to try.
    http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm/repodata/repomd.xml: [Errno -1] Error importing repomd.xml for Percona: Damaged repomd.xml file"}
    failed: [server2] (item=[u'pmm-client']) => {"changed": false, "item": ["pmm-client"], "msg": "Failure talking to yum: failure: repodata/repomd.xml from Percona: [Errno 256] No more mirrors to try.
    http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm/repodata/repomd.xml: [Errno -1] Error importing repomd.xml for Percona: Damaged repomd.xml file"}

2. Using yum_repository module (Try 2)

    - name: "Setting up percona repository"
      yum_repository:
        name: "Percona"
        description: "Percona yum repository"
        baseurl: "http://www.percona.com/downloads/percona-release/redhat/latest/"

    - name: "Installing PMM client package"
      yum: pkg={{item}} state=installed
      with_items:
      - pmm-client

Result

    TASK [pmmhosts : Setting up percona repository] **********************************************************************
    changed: [server1]
    changed: [server2]

    TASK [pmmhosts : Installing PMM client package] **********************************************************************
    failed: [server1] (item=[u'pmm-client']) => {"changed": false, "item": ["pmm-client"], "msg": "Failure talking to yum: failure: repodata/repomd.xml from Percona: [Errno 256] No more mirrors to try.
    http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm/repodata/repomd.xml: [Errno -1] Error importing repomd.xml for Percona: Damaged repomd.xml file"}
    failed: [server2] (item=[u'pmm-client']) => {"changed": false, "item": ["pmm-client"], "msg": "Failure talking to yum: failure: repodata/repomd.xml from Percona: [Errno 256] No more mirrors to try.
    http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm/repodata/repomd.xml: [Errno -1] Error importing repomd.xml for Percona: Damaged repomd.xml file"}

3. Using shell module (Try 1)

    - name: "Setting up percona repository"
      shell: "yum install -y http://www.percona.com/redir/downloads/percona-release/redhat/latest/percona-release-0.1-4.noarch.rpm"

    - name: "Installing PMM client package"
      yum: pkg={{item}} state=installed
      with_items:
      - pmm-client

Result (Run 1)

    TASK [pmmhosts : Setting up percona repository] **********************************************************************
    changed: [server1]
    changed: [server2]
    TASK [pmmhosts : Installing PMM client package] **********************************************************************
    changed: [server1] => (item=[u'pmm-client'])
    changed: [server2] => (item=[u'pmm-client'])

Result (Run 2)

    TASK [pmmhosts : Setting up percona repository] **********************************************************************
    fatal: [server1]: FAILED! => {"changed": true, "cmd": "yum install -y http://www.percona.com/redir/downloads/percona-release/redhat/latest/percona-release-0.1-4.noarch.rpm", "delta": "0:00:01.363009", "end": "2018-02-28 16:31:23.728102", "msg": "non-zero return code", "rc": 1, "start": "2018-02-28 16:31:22.365093", "stderr": "Error: Nothing to do", "stderr_lines": ["Error: Nothing to do"], "stdout": "Loaded plugins: fastestmirror
    Examining /var/tmp/yum-root-5raeIL/percona-release-0.1-4.noarch.rpm: percona-release-0.1-4.noarch
    /var/tmp/yum-root-5raeIL/percona-release-0.1-4.noarch.rpm: does not update installed package.", "stdout_lines": ["Loaded plugins: fastestmirror", "Examining /var/tmp/yum-root-5raeIL/percona-release-0.1-4.noarch.rpm: percona-release-0.1-4.noarch", "/var/tmp/yum-root-5raeIL/percona-release-0.1-4.noarch.rpm: does not update installed package."]}
    fatal: [server2]: FAILED! => {"changed": true, "cmd": "yum install -y http://www.percona.com/redir/downloads/percona-release/redhat/latest/percona-release-0.1-4.noarch.rpm", "delta": "0:00:01.363009", "end": "2018-02-28 16:31:23.728102", "msg": "non-zero return code", "rc": 1, "start": "2018-02-28 16:31:22.365093", "stderr": "Error: Nothing to do", "stderr_lines": ["Error: Nothing to do"], "stdout": "Loaded plugins: fastestmirror
    Examining /var/tmp/yum-root-5raeIL/percona-release-0.1-4.noarch.rpm: percona-release-0.1-4.noarch
    /var/tmp/yum-root-5raeIL/percona-release-0.1-4.noarch.rpm: does not update installed package.", "stdout_lines": ["Loaded plugins: fastestmirror", "Examining /var/tmp/yum-root-5raeIL/percona-release-0.1-4.noarch.rpm: percona-release-0.1-4.noarch", "/var/tmp/yum-root-5raeIL/percona-release-0.1-4.noarch.rpm: does not update installed package."]}

Conclusions:

So far, using yum_repository module, I'm installing the repository successfully. However, I'm not able to get any packages from this repository so doing "yum install" is no longer possible. On the other hand, using shell module, I'm able to install the repository for the first time, then installing the package runs normally. However, I'm not able to reproduce the state again due to error of the repository already installed.


Solution

I'd modify your 3rd attempt to use the yum module to install the Percona rpm which sets up the repository and installs the required GPG key(s) which will work idempotently:

- name: "Setting up percona repository"
  yum:
    name: "http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm"
    state: present

- name: Installing PMM client package...
....


Answered By - Yeroc
Answer Checked By - Senaida (WPSolving Volunteer)