添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more

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.

I know what you are trying to say. Still, if I do it by the shell like command, there are no errors. There should be a way to do it with the yum_repository module. Since this should be the correct / ansible way of doing it – BlackStar Feb 28 '18 at 22:59 Yes, but the problem is not ansible. As the error message suggests - yum fails to install the package, not andible – man0v Feb 28 '18 at 23:01

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"
    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...
                You're welcome.  You could probably get it working with your first approach using the yum_repository module as well.  Probably what you're missing there is the gpgkeys setting but it's likely simplest to use the rpm that Percona provides to handle that end of the setup.
– Yeroc
                Mar 1 '18 at 21:58