0

I've the following Puppet manifest:

# PHP Configuration
class php {

  exec { "php5enmod $module":
    path => "/usr/sbin",
    command => "php5enmod $module",
  }

  file {'/etc/php5/conf.d/upload_limits.ini':
    ensure => present,
    owner => root, group => root, mode => 444,
    notify => [ Exec["php5enmod upload_limits"], Service["apache2"] ],
    content => "post_max_size = 16M \nupload_max_filesize = 16M \n",
  }
  file {'/etc/php5/conf.d/memory_limits.ini':
    ensure => present,
    owner => root, group => root, mode => 444,
    notify => [ Exec["php5enmod memory_limits"], Service["apache2"] ],
    content => "memory_limit = 256M \n",
  }
}
include php

How I can create exec to use in notify by passing the parameter dynamically? It's something that's possible, or there is another better way of doing it?


The current code gives me errors like:

Error: Could not find dependent Exec[php5enmod upload_limits] for File[/etc/php5/conf.d/upload_limits.ini]

0

2 Answers 2

4

When this is running the exec first gets declared.
At that point $module is not set, so the exec title is php5enmod.
You are not passing a variable here, this is just a name.

In such a case a defined type makes more sense.
Like this:

define php5enmod() {
  exec { "php5enmod_${title}":
    path        => "/usr/sbin",
    command     => "php5enmod $title",
    refreshonly => true,
    notify      => Service["apache2"]
  }
}

class php {

  php5enmod{ 'upload_limits': }
  file {'/etc/php5/conf.d/upload_limits.ini':
    ensure  => present,
    owner   => 'root',
    group   => 'root',
    mode    => '0444',
    content => "post_max_size = 16M \nupload_max_filesize = 16M \n",
    notify  => Php5enmod["upload_limits"],
  }

  php5enmod{ 'memory_limits': }
  file {'/etc/php5/conf.d/memory_limits.ini':
    ensure  => present,
    owner   => 'root',
    group   => 'root',
    mode    => '0444',
    content => "memory_limit = 256M \n",
    notify  => Php5enmod["memory_limits"],
  }

}

include php

Normally the define shouldn't be there.
It should probably be php::php5enmod() and have it's own file.
This is just to show the general concept.

1
  • This mostly works for me on Puppet 4.10.9 except the line: notify => Php5enmod["upload_limits"], needs to be: notify => Exec["php5enmod_upload_limits"], and then it works correctly. I wonder if the syntax above used to work on a previous version? I also used manifests/php5enmod.pp and scoped the define as php::php5enmod both in the define and in the instantiation from the class. Jan 16, 2018 at 21:14
2

Reverse your thinking! Use Subscribe to link your variably-named Exec (bad form, IMHO) to the File. Subscribe and Notify are complimentary; they do the same thing, but in differing directions.

Try something like this?

  exec { "php5enmod $module":
    path => "/usr/sbin",
    command => "php5enmod $module",
    subscribe => [File["/etc/php5/conf.d/upload_limits.ini"], File["/etc/php5/conf.d/memory_limits.ini"],
  }

  file {'/etc/php5/conf.d/upload_limits.ini':
    ensure => present,
    owner => root, group => root, mode => 444,
    notify => Service["apache2"]
    content => "post_max_size = 16M \nupload_max_filesize = 16M \n",
  }
  file {'/etc/php5/conf.d/memory_limits.ini':
    ensure => present,
    owner => root, group => root, mode => 444,
    notify => Service["apache2"]
    content => "memory_limit = 256M \n",
  }

Completely untested, but I think that'll get you started at least...

1
  • 1
    This has a flaw: $module is not set when exec gets declared. Meaning that the command getting executed will always be incomplete. See my answer for details
    – faker
    Apr 20, 2015 at 6:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .