0

First off, I know there are a lot of questions regarding this error and I have checked them all, mine is not solved using any of their solutions however.

I am working for the first time with Puppet / Ruby and am having the following issue.

I created this function:

module Puppet::Parser::Functions newfunction(:phpversion, :type => :rvalue) do %x["/usr/bin/php -r 'echo PHP_MAJOR_VERSION . \".\" . PHP_MINOR_VERSION;'"] end end 

And when I call it in my manifest file using:

$phpversion = phpversion() 

It throws, when I execute the agent, the error "Error: Could not retrieve catalog from remote server: Error 400 on SERVER: wrong number of arguments (1 for 0) at /etc/puppetlabs/puppet/modules/x/manifests/somefile.pp:123 on node foo.example.bar"

I tried adding |args| after the do statement and removing :type but it keeps throwing the same error. when I use $phpversion = phpversion it just thinks its a text string instead of a function (which I expected, but tried anyway).

Any help would be greatly appreciated.

2
  • 4
    Are you aware that this function will find the puppet master's php version, not the version on the node being configured? Commented Jun 24, 2015 at 13:51
  • At the time I wasn't and got pointed towards it by a colleague, thanks for the information though as I would've continued thinking it would've been the client's version. Either way I'm still quite curious as to how to solve this issue so I can prevent/fix it in the future Commented Jun 24, 2015 at 17:36

1 Answer 1

3

If you're trying to get the version of php, it'd probably be easier to do it as a fact:

Facter.add(:phpversion) do setcode do if Facter::Util::Resolution.which('php') Facter::Util::Resolution.exec('/usr/bin/php -r 'echo PHP_MAJOR_VERSION . \".\" . PHP_MINOR_VERSION;'"').lines.first.split(/"/)[1].strip end end end 

Put this a directory lib/facter/ in your module, then reference it in your manifest as $::phpversion

Sign up to request clarification or add additional context in comments.

1 Comment

Looks like the quotes in the exec need to be escaped.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.