Setting facts as environment variables
Another handy way to get information into Puppet and Facter is to pass it using environment variables. Any environment variable whose name starts with FACTER_
will be interpreted as a fact. For example, ask facter the value of hello using the following command:
[root@cookbook ~]# facter -p hello Hello, world
Now override the value with an environment variable and ask again:
[root@cookbook ~]# FACTER_hello='Howdy!' facter -p hello Howdy!
It works just as well with Puppet, so let's run through an example.
How to do it...
In this example we'll set a fact using an environment variable:
- Keep the node definition for cookbook the same as our last example:
node cookbook { notify {"$::hello": } }
- Run the following command:
[root@cookbook ~]# FACTER_hello="Hallo Welt" puppet agent -t Info: Caching catalog for cookbook.example.com Info: Applying configuration version '1416212026' Notice: Hallo Welt Notice: /Stage[main...