简体   繁体   English

木偶事实,如何从Yaml文件设置自定义事实?

[英]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. 我希望能够为p设置许多不同的自定义事实。 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. 看起来有一种方法可以将所有这些列出在yaml文件中,然后将它们加载到其中,但是文档中没有确切的命令来执行此操作。

How can I set custom facts from a yml file? 如何从yml文件设置自定义事实? 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? 如果我做不到,是否有其他方法可以设置事实,而不必构建都通过Facter.add函数运行的自定义红宝石脚本?

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. 存储它们的正确位置在相关模块内的facts.d目录中。 Note the documentation on where to store external facts here: https://docs.puppet.com/facter/3.8/custom_facts.html#fact-locations . 请在此处注意有关存储外部事实的文档: 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. 这些事实文件将自动复制到客户端节点,并在Puppet代理执行开始附近的pluginsync期间加载。 Recall that this will occur for any catalog that includes the modulepath this module is located in (normally the relevant directory environment). 回想一下,对于包含此模块所在模块modulepath任何目录(通常是相关目录环境),都会发生这种情况。

Given an example module foo , the directory structure would look like: 给定一个示例模块foo ,目录结构如下所示:

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 . 然后,您可以按照常规方式在Puppet代码中使用这些事实,例如$facts['fact_name']或较旧的Facter $::fact_name You can also view them on clients using the puppet plugin argument to Facter via facter -p . 您还可以通过Facter facter -p使用Facter的puppet插件参数在客户端上查看它们。

You can just write your facts in a yaml file in the facts.d directory. 您可以将事实写在facts.d目录中的yaml文件中。

For example, you can create a /etc/facter/facts.d/my_custom_fact.yaml : 例如,您可以创建一个/etc/facter/facts.d/my_custom_fact.yaml

my_fact: 42

This will create a fact my_fact, with value 42. 这将创建一个事实my_fact,其值为42。

You can check if it worked by typing facter , and check if you fact is present. 您可以通过键入facter来检查它是否有效,并检查是否存在事实。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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