2

I'm trying to get PHP 7.4 installed on my RHEL 8 system with Puppet, but can't get the package declaration right to disable php and enable php:7.4 with dnf. The Puppet Package documentation doesn't describe well, and I wasn't able to learn anything from this post: Puppet 5.5.22, dnfmodule reset

Right now, Puppet installs 7.2, and then these commands are run manually to upgrade.

dnf module disable php
dnf module enable php:7.4
dnf upgrade php

How do I do this all with puppet?

2 Answers2

1

Puppet's resource package has the provider attribute, which accepts dnfmodule as a value. This way, you can enable and disable module streams easily:

  # Uninstall whatever eventual pre-enabled stream
  # Different title, and module name in "module" attribute,
  # only to avoid conflict with actual 'php' package
  package { 'php:module':
    ensure   => disabled,
    name     => 'php',
    provider => dnfmodule,      # Configs module, not package
  }
  package { 'php:7.4':          # Use resource title to choose stream
    ensure      => present,
    provider    => dnfmodule,
    enable_only => true,        # Don't install whole module
  }
  package {
    'php': ensure => present,   # From enabled 7.4 stream
  }

Confirm with:

dnf module list php
rpm -q php
0

You could see if there is a module on the Puppet Forge, but failing that you can use exec resources with the creates argument (if the commands run create a specific file). Failing that, use the exec resource but tack on a touch command to create your own marker to keep the resource idempotent.

E.G:

exec {
  cmd => 'dnf module disable php && touch /etc/.dnf-php-disabled`
  creates => '/etc/.dnf-php-disabled'
}
shearn89
  • 3,403
  • 2
  • 15
  • 39