Jira (PUP-11696) Unless parameter of Exec evaluated before Requires

6 views
Skip to first unread message

Dagan McGregor (Jira)

unread,
Jan 5, 2023, 12:06:02 AM1/5/23
to puppe...@googlegroups.com
Dagan McGregor created an issue
 
Puppet / Bug PUP-11696
Unless parameter of Exec evaluated before Requires
Issue Type: Bug Bug
Affects Versions: PUP 6.28.0
Assignee: Unassigned
Components: Language
Created: 2023/01/04 9:05 PM
Priority: Normal Normal
Reporter: Dagan McGregor

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.

 

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.20.11#820011-sha1:0629dd8)
Atlassian logo

Morgan Rhodes (Jira)

unread,
Jan 10, 2023, 4:20:01 PM1/10/23
to puppe...@googlegroups.com
Morgan Rhodes commented on Bug PUP-11696
 
Re: Unless parameter of Exec evaluated before Requires

Hi Dagan McGregor,

Does this work as expected if you run without --noop? --noop isn't a perfect simulation and these sorts of errors are hard to avoid in situations like this.

Morgan Rhodes (Jira)

unread,
Jan 10, 2023, 4:20:03 PM1/10/23
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages