Setting facts as environment variables
Another handy way to get information into Puppet and Facter is to pass it in using environment variables. Any environment variable whose name starts with FACTER_
will be interpreted as a fact. For example, try the following command:
ubuntu@cookbook:~/puppet$ FACTER_moonphase=full facter moonphase full
It works just as well with Puppet, so let's run through an example.
How to do it...
Follow these steps to see how to set facts using environment variables:
Modify your
manifests/nodes.pp
file as follows:node 'cookbook' { notify { "The moon is $::moonphase": } }
Run the following command:
ubuntu@cookbook:~/puppet$ FACTER_moonphase="waxing crescent" puppet apply manifests/site.pp Notice: The moon is waxing crescent Notice: /Stage[main]//Node[cookbook]/Notify[The moon is waxing crescent]/message: defined 'message' as 'The moon is waxing crescent' Notice: Finished catalog run in 0.06 seconds