【问题标题】:Hiera isn't resolving FactsHiera 没有解决 Facts
【发布时间】:2018-07-29 17:09:55
【问题描述】:

我在使用 Puppet 和 Hiera 时遇到了一些问题,因为 Hiera 似乎没有使用我在模板中要求的事实。

我有一个/etc/puppetlabs/puppet/hiera.yaml 文件,其中包含一个简单的示例层次结构:

---
version: 5

defaults:
  datadir: "/etc/puppetlabs/code/environments/%{::environment}/hieradata"
  data_hash: yaml_data

hierarchy:
  - name: "Per-node data"
    path: "nodes/%{trusted.certname}.yaml"

  - name: "Per-OS defaults"
    path: "os/%{facts.os.family}.yaml"

  - name: "Common data"
    path: "common.yaml"

然后我有一个 puppet 代理,它已经运行并将它的事实发送给 Puppet。当我测试它的查找时,变量都扩展为空字符串:

> puppet lookup profiles --environment production --node puppet.example.local --explain

Searching for "lookup_options"
  Global Data Provider (hiera configuration version 5)
    Using configuration "/etc/puppetlabs/puppet/hiera.yaml"
    Merge strategy hash
      Hierarchy entry "Per-node data"
        Path "/etc/puppetlabs/code/environments/production/hieradata/nodes/test-.yaml"
          Original path: "nodes/test-%{trusted.certname}.yaml"
          Path not found
      Hierarchy entry "Per-OS defaults"
        Path "/etc/puppetlabs/code/environments/production/hieradata/os/.yaml"
          Original path: "os/%{facts.os.family}.yaml"
          Path not found
      Hierarchy entry "Common data"
        Path "/etc/puppetlabs/code/environments/production/hieradata/common.yaml"
          Original path: "common.yaml"
          No such key: "lookup_options"
Searching for "profiles"
  Global Data Provider (hiera configuration version 5)
    Using configuration "/etc/puppetlabs/puppet/hiera.yaml"
    Hierarchy entry "Per-node data"
      Path "/etc/puppetlabs/code/environments/production/hieradata/nodes/.yaml"
        Original path: "nodes/test-%{trusted.certname}.yaml"
        Path not found
    Hierarchy entry "Per-OS defaults"
      Path "/etc/puppetlabs/code/environments/production/hieradata/os/.yaml"
        Original path: "os/%{facts.os.family}.yaml"
        Path not found
    Hierarchy entry "Common data"
      Path "/etc/puppetlabs/code/environments/production/hieradata/common.yaml"
        Original path: "common.yaml"
        No such key: "profiles"
Function lookup() did not find a value for the name 'profiles'

未找到该值,但我认为这无关紧要,因为它甚至没有寻找任何真实文件,这些文件都显示为 nodes/.yamlos/.yaml

如果我再次使用--debug 运行命令,我可以看到包含事实的节点信息转储:

Debug: Facter: fact "osfamily" has resolved to "RedHat".
...
Debug: Facter: fact "os" has resolved to {
  architecture => "x86_64",
  family => "RedHat",
  hardware => "x86_64",
  name => "CentOS",
  release => {
    full => "7.4.1708",
    major => "7",
    minor => "4"
  },

傀儡:5.4.0

【问题讨论】:

  • 这是Facter 3.x?
  • @MattSchuchard facter --version 说 3.10.0。
  • 您没有在命令行上指定任何事实。 puppet lookup 命令将获取并使用指定节点的最新事实如果它们记录在 puppetdb 中并且该命令在有权访问的节点上运行。它不会像 puppet agentpuppet apply 那样自动收集事实。

标签: puppet hiera


【解决方案1】:

在以下路径中指定您的事实文件

/etc/facter/facts.d/${your_component_facts}.sh

并授予所需的权限:

chmod +x /etc/facter/facts.d/${your_component_facts}.sh

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-18
    • 2015-12-26
    • 1970-01-01
    • 2016-06-06
    • 2015-07-22
    • 2021-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多