I am trying to make Ansible force install an rpm package to overwrite an existing one.

This works:

- name: RPM force install nodesource and yum clean all
  shell: rpm -i --nosignature --force "https://rpm.nodesource.com/{{ nodejs_rhel_rpm_dir }}/el/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/nodesource-release-el{{ ansible_distribution_major_version }}-1.noarch.rpm" && yum clean all
    executable: /bin/bash
    - nodejs

I would PREFER to just do it like this, and not use shell module:

- name: Install nodesource npm/node packages
    name: "https://rpm.nodesource.com/{{ nodejs_rhel_rpm_dir }}/el/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/nodesource-release-el{{ ansible_distribution_major_version }}-1.noarch.rpm"
    state: latest
    update_cache: yes
    - nodejs

However I cannot seem to force overwrite the existing installed version without using rpm directly. What's the best method to do this in Ansible without using shell which is against best practice with configuration mgmt.

Am I going to be forced to uninstall & reinstall the package in two steps?


To make this clear, the .rpm being installed is DIFFERENT from the currently installed one.

Currently installed one: https://rpm.nodesource.com/pub_8.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm

The NEW one is: https://rpm.nodesource.com/pub_10.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm


2 Answers 2


The reason this is happening is that the upstream vendor didn't create the packages with sane version information.

These are nodesource-release RPM files for NodeJS 8.x and 10.x respectively, which install the corresponding yum repository.

I downloaded each of them and looked at their reported information. Both of them had identical name, version and release:

Name        : nodesource-release
Version     : el7
Release     : 1
Architecture: noarch

There is no way for rpm or yum to tell these packages apart. Their metadata make them look identical.

I would first complain to the vendor about this, so that hopefully they will repackage these files to give them some distinguishing characteristics. It would be logical to use the corresponding NodeJS version. In the meantime, I think you're stuck with your workaround. Ansible packaging modules do not provide for "reinstalling" a package.

  • Thanks very much, very helpful. All this time I thought it was the installer that was the problem and hadn't really given much thought to the packages themselves. Great work.
    – emmdee
    Sep 11, 2019 at 23:08

This kind of goes against how Ansible is designed to work. Ansible recognizes that the desired package is already installed, thus is skips over it. There is no force option for the yum module.

Your best bet is to uninstall the package and reinstall. It can be done within the same playbook.

Is there a particular reason why you're trying to force it?

  • 1
    I would prefer to not force it, just trying to install the new version of the rpm. from the site. It's a different rpm from the one that's already installed.
    – emmdee
    Aug 30, 2019 at 20:55
  • See the "preferred" method in my question for what I'm "actually" trying to do. The rpm --force is a workaround (that works)
    – emmdee
    Aug 30, 2019 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.