How would you use facter and puppet to determine if the OS is running Cent 6.x or Cent 5.x ?
facter operatingsystemrelease
6.4
I only care about the major release (6)
I've thought about using awk, but there must be a better way that is more 'puppet manifest' friendly.
#This works, but is ugly trying to use this in a puppet manifest
facter operatingsystemrelease |awk -F. '{print $1}'
6
Update:
It looks like the newer versions of facter have some additional information about major releases that isn't in my version. My initial provisioning needs to assume that facter is out of date.
facter --version
1.6.4
puppet --version
2.7.20
I've tried searching for any additional facts that might show the major release, with the following command
facter |grep 6
There is operatingsystemmajrelease
If you have redhat-lsb-core package installed, facter will get as well the family of lsb-provided facts (which includes lsbmajdistrelease):
NOTE: You need at least Facter 1.7 in order have
operatingsystemmajrelease
. Core facts in Facter 1.6 are quite limited.I'm guessing that you are trying to make some sort of decision based off of the install version.
You can use regexes in your logic.
So something like:
or if
if
is more your style:Remember that all factor facts are available in global scope variables to your manifests.
If you have a mixed environment you will probably want to wrap that in in something like:
With Puppet 5.5+ you should use a part of the compound
os
fact asoperatingsystemmajrelease
fact is a legacy fact now.An example value of this fact:
Also please note that its value is a string, not an integer so remember about this when making comparisons: