1
votes

I am trying to install a bunch of RPMs that come from a tarball stored on a central server. These RPMs have dependencies on each other but that's not a problem when I install them manually, I just use:

# yum install *rpm

and they are all installed, yum works out that the dependencies are included in the other RPMs.

Using Ansible I transfer the tarball using the following play:

- name: Unpack installation bundle
  unarchive:
    src: /media/shared/archive/{{ sw }}-{{ os }}.tar.gz
    dest: $HOME

This copies the tarball to the remote server and unpacks it. This works.

The problem is when I try and install the RPMs. I currently have the following plays:

- name: Finding RPM files
  find:
    paths: "$HOME/{{ sw }}"
    patterns: "*.rpm"
  register: rpm_result

- name: Install RPM
  yum:
    name: "{{ item.path }}"
    state: present
  with_items: "{{ rpm_result.files }}"
  become: yes
  become_method: sudo

The rpm_result.files is correctly populated with all of the RPMs but some of them are not installed because the yum module seems to be installing them individually even though the documentation claims that it does them together (see "Notes" in http://docs.ansible.com/ansible/latest/yum_module.html) When I run the playbook I get complaints about missing dependencies:

"Error: Package: snmpagent-1.2.0.0-1.el6.x86_64 (/snmpagent-1.2.0.0-1.el6.x86_64)
       Requires: utils >= 3.1.0.0\n", "rc": 1,

(Output shortened and sliced up to make it easier to read)

This is the same error I get if I try and install the RPMs one at a time.

How do I persuade yum to install all RPMs at the same time?

I am running ansible-playbook v2.4.0.0, so it's reasonably recent.

3
I'd like to know when this gets fixed. (Not sure how to "follow" this question without adding a comment.) - mr.zog

3 Answers

5
votes

To persuade yum to install all the rpms at the same time, to handle dependencies resolved based on the list of files in a specific directory, you need to pass the whole list of rpms to the yum command. The following code worked for me.

# Get a list of rpms from a directory
- name: find rpm files and register the result 
  find:
    paths: /opt/rpms
    patterns: "*.rpm"
  register: rpm_files

# Create a list of the rpms to use with the yum install command
- set_fact:
    rpm_list: "{{ rpm_files.files | map(attribute='path') | list}}"

# Use yum to install with a list
- name: install rpm files using rpm_list
  yum:
    name: "{{rpm_list}}"
    state: present
0
votes

I'm aware of a workaround and a solution.

The workaround is to run yum install in a command or shell module call.

The solution is to load the RPM files into a repository and configure it as a package source, which generally makes dependency resolution easier.

0
votes

There are multiple ways to do that. You could directly source your rpm packages first and then install them like @ChrisSteele has mentioned or you could register the external repo URL in /etc/yum.repos.d/.

For the 2nd options, you could basically create 2 tasks in your playbook.

1) for adding a .repo file within the directory structure /etc/yum.repos.d/ in your remote server. This will look something like below:

- name: Add .repo file where the rpm packages are present
  yum_repository:
    name: packages.repo   #can give any name with .repo extension
    description: adding repo URL in packages.repo file in yum.repo.d
    baseurl: "https://###.nexus.com/content/repositories/anything###/Packages/"
    enabled: yes
    gpgcheck: no

2) a loop of all the packages that you would like to install using yum module.

- name: Install multiple rpm packages with its dependencies
  yum:
    name: "{{ item }}"
    state: present
  loop:
    - rpm_package_dependency_1       (need not mention .rpm extension here)
    - rpm_package_dependency_2
    - rpm_package_1 
    - rpm_package_2