I have this configuration:
file {
"/tmp/apc.ini":
source => "puppet:///modules/uc/php/apc.ini",
require => Package["php-apc"]
}
exec {
"Add apc.ini to php mods-available":
command => 'mv /tmp/apc.ini /etc/php5/mods-available/apc.ini',
onlyif => "test -d /etc/php5/mods-available",
require => File["/tmp/apc.ini"]
}
exec {
"Add apc.ini to php conf.d":
command => 'mv /tmp/apc.ini /etc/php5/conf.d/apc.ini',
unless => "test -d /etc/php5/mods-available",
require => File["/tmp/apc.ini"]
}
I'd like to be able to simplify this so that the /tmp/apc.ini file isn't created every time I run puppet agent --test
For the moment, I get the following output:
info: Retrieving plugin
info: Loading facts in /var/lib/puppet/lib/facter/root_home.rb
info: Loading facts in /var/lib/puppet/lib/facter/concat_basedir.rb
info: Loading facts in /var/lib/puppet/lib/facter/postgres.rb
info: Loading facts in /var/lib/puppet/lib/facter/puppet_vardir.rb
info: Caching catalog for frontapp0.demo.infra.universcine.com
info: Applying configuration version '1376302253'
notice: /Stage[main]/Uc::Role::Php/File[/tmp/apc.ini]/ensure: defined content as '{md5}e5f5a158bd83469ce031b20ec72ce717'
notice: /Stage[main]/Uc::Role::Php/Exec[Add apc.ini to php mods-available]/returns: executed successfully
notice: Finished catalog run in 36.12 seconds
What can I try ?
UPDATE The goal is to have apc.ini either in mods-available or in conf.d, depending on whether the former exists or not
A simple way to accomplish this would be to deploy a custom fact. If you're using the
puppet-stdlib
module, you can write custom facts in the language of your choice by dropping an executable script into/etc/facter/facts.d
(see this article for details). For example, if you created a script/etc/facter/facts.d/apc_ini_path
with the following contents (and made sure it was executable):Then you would have available a fact "apc_ini_path", and you could do this:
Of course, if you're comfortable with Ruby you can also just drop a Ruby fact into
YOURMODULE/lib/facter/yourfact.rb
using the examples presented in the same article. They provide a sample Ruby fact that's pretty trivial:It should be fairly easy to replace this with a directory existence check.