community.general.icinga2 inventory – Icinga2清单源

注意

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

如果您使用的是 ansible 软件包,则可能已安装此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用: ansible-galaxy collection install community.general

要在playbook中使用它,请指定: community.general.icinga2

community.general 3.7.0 中的新增功能

概要

  • 从Icinga2 API获取清单主机。

  • 使用配置文件作为清单源,它必须以 .icinga2.yml.icinga2.yaml 结尾。

参数

参数

注释

compose

字典

在community.general 4.4.0中添加

从jinja2表达式创建变量。

默认值: {}

group_by_hostgroups

布尔值

在community.general 8.4.0中添加

使用Icinga2主机组作为组。

选项

  • false

  • true ← (默认)

groups

字典

在community.general 4.4.0中添加

基于Jinja2条件将主机添加到组。

默认值: {}

host_filter

字符串

有效的Icinga2 API主机过滤器。留空表示不进行过滤

inventory_attr

字符串

在community.general 4.2.0中添加

允许基于不同的属性覆盖清单名称。

这允许更改限制的使用方式。

当前默认值 address 有时不唯一或不存在。我们建议改为使用 name

选项

  • "name"

  • "display_name"

  • "address" ← (默认)

keyed_groups

列表 / 元素=字典

在community.general 4.4.0中添加

基于变量的值将主机添加到组。

默认值: []

default_value

字符串

在ansible-core 2.12中添加

当主机变量的值为空字符串时的默认值。

此选项与 keyed_groups[].trailing_separator 互斥。

key

字符串

用于生成组的输入字典中的键。

parent_group

字符串

键控组的父组。

prefix

字符串

键控组名将以此前缀开头。

默认值: ""

separator

字符串

用于构建键控组名的分隔符。

默认值: "_"

trailing_separator

布尔值

在ansible-core 2.12中添加

将此选项设置为 false 以在值为空字符串时省略主机变量后的 keyed_groups[].separator

此选项与 keyed_groups[].default_value 互斥。

选项

  • false

  • true ← (默认)

leading_separator

布尔值

在ansible-core 2.11中添加

keyed_groups 结合使用。

默认情况下,没有提供前缀或分隔符的键控组的名称将以下划线开头。

这是因为默认前缀为 "",默认分隔符为 "_"

如果未给出前缀,则将此选项设置为 false 以省略前导下划线(或其他分隔符)。

如果组名是从映射中导出的,则仍然使用分隔符来连接项目。

为了完全不在组名中使用分隔符,请将键控组的分隔符设置为空字符串。

选项

  • false

  • true ← (默认)

密码

字符串 / 必需

查询 API 的密码。

插件

字符串 / 必需

插件名称。

选项

  • “community.general.icinga2”

严格模式

布尔值

在community.general 4.4.0中添加

如果 yes 将无效条目设为致命错误,否则跳过并继续。

由于可以在表达式中使用事实,因此它们可能并不总是可用,并且我们默认忽略这些错误。

选项

  • false ← (默认)

  • true

URL

字符串 / 必需

Icinga2 API 的根 URL。

使用额外变量

布尔值

在ansible-core 2.11中添加

将额外变量合并到可用于组合的变量中(最高优先级)。

选项

  • false ← (默认)

  • true

配置

用户名

字符串 / 必需

查询 API 的用户名。

验证证书

布尔值

启用或禁用 SSL 证书验证。

选项

  • false

  • true ← (默认)

示例

# my.icinga2.yml
plugin: community.general.icinga2
url: https://127.0.0.1:5665
user: ansible
password: secure
host_filter: \"linux-servers\" in host.groups
validate_certs: false  # only do this when connecting to localhost!
inventory_attr: name
groups:
  # simple name matching
  webservers: inventory_hostname.startswith('web')

  # using icinga2 template
  databaseservers: "'db-template' in (icinga2_attributes.templates|list)"

compose:
  # set all icinga2 attributes to a host variable 'icinga2_attrs'
  icinga2_attrs: icinga2_attributes

  # set 'ansible_user' and 'ansible_port' from icinga2 host vars
  ansible_user: icinga2_attributes.vars.ansible_user
  ansible_port: icinga2_attributes.vars.ansible_port | default(22)

作者

  • Cliff Hults (@BongoEADGC6)

提示

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