我有以下 Puppet 清单:
# 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
如何通过动态传递参数exec
来创建以供使用notify
?这是可能的,还是有其他更好的方法?
当前代码给出如下错误:
错误:找不到文件 [/etc/php5/conf.d/upload_limits.ini] 的依赖 Exec [php5enmod upload_limits]
答案1
当此程序运行时,exec
第一个被声明。
此时 $module 尚未设置,因此 exec 标题为php5enmod
。
您在这里没有传递变量,这只是一个名称。
在这种情况下定义类型更有意义。
像这样:
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
通常define
不应该在那里。
它应该在那里php::php5enmod()
并且有自己的文件。
这只是为了展示一般概念。
答案2
逆向思维!使用Subscribe
将您的变量命名Exec
(错误的形式,恕我直言)链接到File
。 Subscribe and Notify
是互补的;它们做同样的事情,只是方向不同。
尝试类似这?
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",
}
完全未经测试,但我认为这至少可以帮助您入门......