How to pass parameter for Exec from notify

execpuppet

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]

Best Answer

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.

Related Topic