0

I've been trying to set a variable in a Puppet manifest that can be used across the puppet run. I have the following variables:

$package             = 'hello'
$package_ensure      = 'present'
$package_version     = '4.4.1'
$package_maj_version = '4'

I'm trying to add another variable:

$ensure

using a BASH If statement using the above variables (since this is a source install I can't use an rpm command to see if the hello program is installed):

if [ -d "/opt/${package}${package_maj_version}" ]; then echo present; else echo absent; fi

but, I haven't been able to find a way to do so. I keep getting errors such as:

Error: Could not parse for environment production: Could not match ${package}${package_maj_version}"

Any help on this would be greatly appreciated.

  • You statement will evaluate to true when `package` and `package_maj_version` are not set since the `/opt/` directory is present on the system. Is this an acceptable behaviour for you? – redxef Mar 30 '17 at 23:17
  • Yes, if `package` and `package_maj_version` were to default to true if those variables are not set would be ok. However, what i need to happen is that both of those are set, so `ensure` can be set correctly every time. So, I basically need each variable to be set in order from top down. – thatguy Mar 30 '17 at 23:48
  • 1
    https://docs.puppet.com/facter/3.6/custom_facts.html#external-facts – Matthew Schuchard Mar 31 '17 at 11:46
  • http://stackoverflow.com/questions/18411795/set-environment-variables-with-puppet to set environment variables during the puppet run. Then in an `exec`. you'd be able to run your bash command using those environment variables (not the puppet variables) – g19fanatic Apr 13 '17 at 17:36

0 Answers0