community.hrobot.robot 库存 – Hetzner Robot 库存来源
注意
此库存插件是 community.hrobot 集合 (版本 2.0.2) 的一部分。
如果您正在使用 ansible
包,则您可能已经安装了此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用: ansible-galaxy collection install community.hrobot
。
要在剧本中使用它,请指定: community.hrobot.robot
。
community.hrobot 1.1.0 中的新增功能
概要
从 Hetzner Robot API 读取服务器。
使用以
robot.yml
或robot.yaml
结尾的 YAML 配置文件。库存插件将来自 https://robot.your-server.de/doc/webservice/en.html#get-server 的所有值(以
hrobot_
开头)添加到服务器的库存中。例如,变量hrobot_dc
包含服务器所在的数据中心。
参数
参数 |
注释 |
---|---|
切换以启用/禁用库存源数据的缓存,需要设置缓存插件才能工作。 选项
配置
|
|
缓存连接数据或路径,请阅读缓存插件文档以了解详细信息。 配置
|
|
要用于库存源数据的缓存插件。 默认值: 配置
|
|
用于缓存插件文件/表的前缀。 默认值: 配置
|
|
缓存持续时间(秒)。 默认值: 配置
|
|
从 jinja2 表达式创建变量。 默认值: |
|
允许选择/取消选择此库存的主机的包含/排除筛选器列表。 筛选器按顺序处理,直到找到第一个 |
|
一个 Jinja2 条件。如果它与主机匹配,则该主机将被 **排除**。 只能指定 |
|
一个 Jinja2 条件。如果它与主机匹配,则该主机将被 **包含**。 只能指定 |
|
根据 Jinja2 条件将主机添加到组。 默认值: |
|
根据变量的值将主机添加到组中。 默认值: |
|
当主机变量的值为空字符串时的默认值。 |
|
用于生成组的输入字典中的键。 |
|
键控组的父组。 |
|
键控组名称将以此前缀开头。 默认值: |
|
用于构建键控组名称的分隔符。 默认值: |
|
将此选项设置为 此选项与 选项
|
|
与 默认情况下,没有提供前缀或分隔符的键控组的名称将以下划线开头。 这是因为默认前缀为 将此选项设置为 如果组名称是从映射中导出的,则仍然使用分隔符来连接项目。 要完全不使用组名称中的分隔符,请将键控组的分隔符设置为空字符串。 选项
|
|
确保这是插件源文件的令牌。 选项
|
|
过滤器值对的字典。 此处列出的可用过滤器是服务器的键,例如 有关可以使用的所有值,请参见https://robot.your-server.de/doc/webservice/en.html#get-server。 此选项在 community.hrobot 2.0.0 之前称为 默认值: |
|
如果为 由于可以在表达式中使用事实,因此它们可能并不总是可用,因此我们默认忽略这些错误。 选项
|
|
将额外的变量合并到可用于组合的变量中(最高优先级)。 选项
配置
|
注释
注意
hetzner_user
和hetzner_password
选项可以使用模板。
示例
# Fetch all hosts in Hetzner Robot
plugin: community.hrobot.robot
# Filters all servers in ready state
filters:
status: ready
# Example showing encrypted credentials and using filters
# (This assumes that Mozilla sops was used to encrypt keys/hetzner.sops.yaml, which contains two values
# hetzner_username and hetzner_password. Needs the community.sops collection to decode that file.)
plugin: community.hrobot.robot
hetzner_user: '{{ (lookup("community.sops.sops", "keys/hetzner.sops.yaml") | from_yaml).hetzner_username }}'
hetzner_password: '{{ (lookup("community.sops.sops", "keys/hetzner.sops.yaml") | from_yaml).hetzner_password }}'
filters:
# Accept all servers in FSN1-DC1 and FSN1-DC2
- include: >-
hrobot_dc in ["FSN1-DC1", "FSN1-DC2"]
# Exclude all servers that didn't match any of the above filters
- exclude: true
# Example using constructed features to create groups
plugin: community.hrobot.robot
simple_filters:
status: ready
traffic: unlimited
# keyed_groups may be used to create custom groups
strict: false
keyed_groups:
# Add e.g. groups for every data center
- key: hrobot_dc
separator: ""
# Use the IP address to connect to the host
compose:
server_name_ip: hrobot_server_name ~ '-' ~ hrobot_server_ip