On 3/15/15 8:04 PM, Jan Schütze wrote: > Hello, > > I have the following use case: For a custom class/type I need to know > which php_version is installed on the machine. So I wrote a custom fact > like this: > > Facter.add('php_version') do > setcode do > Facter::Util::Resolution.exec('/usr/bin/php -i | /bin/egrep -e "^PHP > Version" | /usr/bin/head -n 1 | /usr/bin/cut -d " " -f 4 | /usr/bin/cut -d > "-" -f 1') > end > end > > It works great. Except: When php is not yet installed (there is a > Package['php'] definition, too). Then it will return an empty string. > > Thus I have to run puppet two times to get the expected result. > > I am sure that this is expected behavior of puppet. How do I handle such > case? > > Regards > > Jan > > -- > > http://dracoblue.net
Hi Jan, Since your module installs PHP, you're kind of stuck with two runs, unless you can provide some sane default when php_version is not present. Suggest implementing your module such that PHP always gets installed and whatever resources require that php_version be present are wrapped in some conditional logic. Here's a quick fix[1] to make your code faster and more portable and not throw errors when PHP is not found. It does require that PHP be in your $PATH. Facter.add("php_version") do setcode do test_exists = "which php 2>&1 >/dev/null ; echo $?" if Facter::Util::Resolution.exec(test_exists) == '0' php_output = Facter::Util::Resolution.exec('php --version') php_output.split[1] end end end [1] - https://gist.github.com/ghoneycutt/42ab87c20f84ec422535 Best regards, -g -- Garrett Honeycutt @learnpuppet Puppet Training with LearnPuppet.com Mobile: +1.206.414.8658 -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/5505F583.4090209%40garretthoneycutt.com. For more options, visit https://groups.google.com/d/optout.