简体   繁体   中英

Puppet facter, how to set custom facts from yaml file?

I want to be able to set a number of different custom facts for puppet. It looks like there is a way to list all of these out in a yaml file and then load them in, but the documentation does not have the exact command to do that.

How can I set custom facts from a yml file? If I cant do this, is there any other method that I can set facts without having to build custom ruby scripts that all run through Facter.add functions?

These types of facts are known as "external facts." They can either be executables, or files in text or supported markup formats. The proper location to store them is in the facts.d directory within the relevant module. Note the documentation on where to store external facts here: https://docs.puppet.com/facter/3.8/custom_facts.html#fact-locations . These fact files will automatically be copied over to client nodes and loaded during pluginsync near the beginning of a Puppet agent execution. Recall that this will occur for any catalog that includes the modulepath this module is located in (normally the relevant directory environment).

Given an example module foo , the directory structure would look like:

foo
|__facts.d
   |__ bar.yaml
   |__ bar.json
   |__ bar.txt

With example content like the following:

# foo/facts.d/bar.yaml
fact_name: fact_value

# foo/facts.d/bar.json
{
  fact_name: fact_value
}

# foo/facts.d/bar.txt
fact_name=fact_value

You can then use these facts as per normal in your Puppet code like $facts['fact_name'] or on older Facter $::fact_name . You can also view them on clients using the puppet plugin argument to Facter via facter -p .

You can just write your facts in a yaml file in the facts.d directory.

For example, you can create a /etc/facter/facts.d/my_custom_fact.yaml :

my_fact: 42

This will create a fact my_fact, with value 42.

You can check if it worked by typing facter , and check if you fact is present.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM