community.general.hiera 查找 – 从 Hiera 数据中获取信息

注意

此查找插件是 community.general 集合(版本 10.1.0)的一部分。

如果您正在使用 ansible 包,您可能已经安装了这个集合。 它不包含在 ansible-core 中。 要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.general。 您需要其他要求才能使用此查找插件,有关详细信息,请参阅 要求

要在剧本中使用它,请指定:community.general.hiera

概要

  • 使用 Hiera 作为 ENC 从 Puppetmaster 节点检索数据。

要求

执行此查找的本地控制器节点需要满足以下要求。

  • hiera (命令行实用程序)

术语

参数

注释

术语

列表 / 元素=字符串 / 必需

要在 Puppetmaster 上查找的键列表。

关键字参数

这描述了查找的关键字参数。 这些是以下示例中的值 key1=value1key2=value2 等:lookup('community.general.hiera', key1=value1, key2=value2, ...)query('community.general.hiera', key1=value1, key2=value2, ...)

参数

注释

config_file

字符串

描述 Hiera 层级的文件。

默认值: "/etc/hiera.yaml"

配置

executable

字符串

执行 Hiera 的二进制文件。

默认值: "/usr/bin/hiera"

配置

备注

注意

  • 当关键字和位置参数一起使用时,位置参数必须在关键字参数之前列出:lookup('community.general.hiera', term1, term2, key1=value1, key2=value2)query('community.general.hiera', term1, term2, key1=value1, key2=value2)

示例

# All this examples depends on hiera.yml that describes the hierarchy

- name: "a value from Hiera 'DB'"
  ansible.builtin.debug:
    msg: "{{ lookup('community.general.hiera', 'foo') }}"

- name: "a value from a Hiera 'DB' on other environment"
  ansible.builtin.debug:
    msg: "{{ lookup('community.general.hiera', 'foo environment=production') }}"

- name: "a value from a Hiera 'DB' for a concrete node"
  ansible.builtin.debug:
    msg: "{{ lookup('community.general.hiera', 'foo fqdn=puppet01.localdomain') }}"

返回值

描述

返回值

列表 / 元素=字符串

与输入键关联的值

已返回: 成功

作者

  • Juan Manuel Parrilla (@jparrill)

提示

每个条目类型的配置条目都具有从低到高的优先级顺序。 例如,列表中较低的变量将覆盖较高的变量。