2

I want to install RPM Fusion repository on Fedora 32 Server virtual machine with Ansible

I've tried various possibility unsuccessfully :

- name: Enable the RPM Fusion repository
command: dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-    free-release-$(rpm -E %fedora).noarch.rpm
when: ansible_facts['os_family'] == 'Fedora' and ansible_facts['distribution_major_version'] == '32'

or

- name: Enable the RPM Fusion repository
  dnf:
    name: 'https://download1.rpmfusion.org/free/fedora/rpmfusion-    free-release-$(rpm -E %fedora).noarch.rpm'
    state: present
  when: ansible_facts['os_family'] == 'Fedora' and ansible_facts['distribution_major_version'] == '32'

Every time the task is skipped

TASK [Enable the RPM Fusion repository] *******************************************************************************
skipping: [my-ip-address]

Do you have an idea?

Thanks!

4

Don't use command to install packages. This has no hope of idempotence and will fail in various and subtle ways.

The reason these are skipped is that the os_family fact is never Fedora. It is set to RedHat on Fedora systems.

You should be checking for the distribution name directly:

when: ansible_distribution == 'Fedora' and ansible_distribution_major_version|int == 32

You've got further problems, though, and your dnf play will also fail, because you tried to use a shell substitution and Ansible won't do anything with that.

Your play should look more like this:

- name: Enable the RPM Fusion repository
  dnf:
    name: "https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-{{ansible_distribution_major_version}}.noarch.rpm"
    state: present
  when: ansible_distribution == 'Fedora'

We're actually providing the version number via substitution, so it will have "32" instead of a random shell command. And of course in this case there is no need to check the distribution version in when: because the relevant version is already provided in the package name.

3
  • Thanks! Michael it's working very well – Maxime Jun 16 '20 at 17:19
  • Amazing! Thanks a lot. I am new to the whole world of Linux so I hope you don't mind me asking, but what is the difference between the when: ansible_distribution == 'Fedora' and when: ansible_distribution == 'Fedora' and ansible_distribution_major_version|int == 32 (I'm assuming 32 is 32-bit)? – telometto Jun 8 at 15:25
  • @telometto No more than 33 is 33-bit or 34 is 34-bit. As it says, it is checking the distro version. – Michael Hampton Jun 8 at 23:53

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.