Ask Your Question

Getting PHP information in a module

asked 2015-09-14 18:38:46 -0500

rombert gravatar image

I'm trying to copy some files based on two pieces information extracted from the PHP executable:

  • thread safety
  • Extension API version

Initially I used a custom fact:

Facter.add('php_extension_version') do
  setcode do
    Facter::Core::Execution.exec("php -i | awk '/^PHP Extension =>/ { print $4}'") || nil

However, this runs before all provisioning is done so the PHP binary is not installed. I resorted to creating, installing and executing a custom shell script which does the provisioning, but that feels completely wrong.

(Also asked this on Stackoverflow at )

I'm wondering if there is a better way than basically executing 20 lines of shell.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2015-09-15 09:57:06 -0500

rombert gravatar image

I ended up writing a provider which can query this information using the php binary ; for me it's important to be able to provision a node using a single puppet agent invocation.

edit flag offensive delete link more

answered 2015-09-14 21:14:43 -0500

GregLarkin gravatar image

You can test for the presence of the PHP binary before computing the value of your custom fact. This will require 2 Puppet agent runs, as you can imagine - the 1st one installs the PHP binary, then the 2nd one computes the custom fact value and possibly provisions more bits based on the value. If that's OK with you, then I think it's the way to go.

Here is an example of using Ruby code to test for the presence of a file before calculating a fact value: If the PHP binary is not present, then you can leave the fact value undefined or some other value that represents "binary not present".

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-09-14 18:38:46 -0500

Seen: 73 times

Last updated: Sep 15 '15