| Puppet Version: 6.28.0 Puppet Server Version: 2019.8.12 OS Name/Version: CentOS 7 We have a module that installs the Postgresql server package, and then two Exec commands that run initdb and create a database. When running a clean install on a new server, testing using --noop, the Exec commands error because the psql command is not available. Even though the Puppet code explicitly requires the Postgresql package to be installed first. Desired Behavior: Puppet should evaluate Requires criteria are met before evaluating Unless or Onlyif parameters Actual Behavior: Puppet evaluates Unless before Requires resulting in run errors for missing installed commands
# Install the package first |
package { $private_module::postgresql_server: |
ensure => installed, |
require => Yumrepo[$private_module::postgresql_repo], |
} |
|
# Breaking the command line options into smaller sections to avoid extremely long lines |
$_version = $private_module::postgresql_version |
|
exec { 'postgresql-initdb': |
command => "/usr/pgsql-${_version}/bin/postgresql-${_version}-setup initdb", |
creates => "/var/lib/pgsql/${_version}/data/postgresql.conf", |
user => 'root', |
require => [ |
Package[$private_module::postgresql_server], |
Package[$private_module::software_package], |
], |
} |
|
exec { 'create-application-db': |
command => "/var/lib/pgsql/${private_module::postgresql_version}/create-application-db.sh", |
unless => "/usr/bin/psql -d ${private_module::db_name}", |
user => 'postgres', |
require => [ |
Exec['postgresql-initdb'], |
File["/var/lib/pgsql/${private_module::postgresql_version}/create-application-db.sh"], |
Package[$private_module::postgresql_server], |
Service[$private_module::postgresql_service], |
], |
}
|
Notice: /Stage[main]/Private_module::Postgresql_server/Package[postgresql14-server]/ensure: current_value 'purged', should be 'present' (noop) (corrective) |
Notice: /Stage[main]/Private_module::Postgresql_server/Exec[postgresql-initdb]/returns: current_value 'notrun', should be ['0'] (noop) (corrective) |
Notice: Class[Private_module::Postgresql_server]: Would have triggered 'refresh' from 5 events |
Notice: /Stage[main]/Private_module::Application_database/File[/var/lib/pgsql/14/create-application-db.sh]/ensure: current_value 'absent', should be 'file' (noop) (corrective) |
Error: /Stage[main]/Private_module::Application_database/Exec[create-application-db]: Could not evaluate: Could not find command '/usr/bin/psql' |
Notice: /Stage[main]/Private_module::Application_database/Exec[import-application-sql]: Dependency Exec[create-application-db] has failures: true |
The difference between the two Exec commands, which rely on the same package, is the second one generates the Error when it tries to run the Unless command. Puppet should be making use of the Requires values to ensure the Unless and Onlyif commands will succeed. |