community.general.linode 清单 – 用于 Linode 的 Ansible 动态清单插件。

注意

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

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

要安装它,请使用:ansible-galaxy collection install community.general。您需要其他要求才能使用此清单插件,请参阅 要求 了解详情。

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

概要

  • 从 Linode API v4 读取清单。

  • 使用以 linode.(yml|yaml) 结尾的 YAML 配置文件。

  • 默认情况下,Linode 标签用作主机名。

  • 默认清单组是从组(Linode 已弃用)而不是标签构建的。

要求

本地控制器节点(执行此清单)需要以下要求。

  • linode_api4 >= 2.0.0

参数

参数

注释

access_token

字符串 / 必需

Linode 账户的个人访问令牌。

配置

cache

布尔值

在 community.general 4.5.0 中添加

切换以启用/禁用清单源数据的缓存,需要设置缓存插件才能工作。

选项

  • false ← (默认)

  • true

配置

cache_connection

字符串

在 community.general 4.5.0 中添加

缓存连接数据或路径,请阅读缓存插件文档以了解具体信息。

配置

cache_plugin

字符串

在 community.general 4.5.0 中添加

用于清单源数据的缓存插件。

默认: "memory"

配置

cache_prefix

字符串

在 community.general 4.5.0 中添加

用于缓存插件文件/表的前缀。

默认: "ansible_inventory_"

配置

cache_timeout

整数

在 community.general 4.5.0 中添加

缓存持续时间(以秒为单位)。

默认: 3600

配置

compose

字典

在 community.general 2.0.0 中添加

从 jinja2 表达式创建变量。

默认: {}

groups

字典

在 community.general 2.0.0 中添加

根据 Jinja2 条件将主机添加到组。

默认: {}

ip_style

字符串

在 community.general 3.6.0 中添加

使用 Linode APIv4 中提供的所有信息填充 hostvars。

选项

  • "plain" ← (默认)

  • "api"

keyed_groups

列表 / elements=dictionary

在 community.general 2.0.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 ← (默认)

plugin

字符串 / 必需

将此标记为“linode”插件的实例。

选项

  • "linode"

  • "community.general.linode"

regions

列表 / 元素=字符串

使用此区域中的实例填充清单。

默认: []

strict

布尔值

在 community.general 2.0.0 中添加

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

由于可以在表达式中使用 facts,因此它们可能并非始终可用,默认情况下我们会忽略这些错误。

选项

  • false ← (默认)

  • true

tags

列表 / 元素=字符串

在 community.general 2.0.0 中添加

仅使用此处列出的至少一个标签的实例填充清单。

默认: []

types

列表 / 元素=字符串

使用此类型的实例填充清单。

默认: []

use_extra_vars

布尔值

在 ansible-core 2.11 中添加

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

选项

  • false ← (默认)

  • true

配置

示例

# Minimal example. `LINODE_ACCESS_TOKEN` is exposed in environment.
plugin: community.general.linode

# You can use Jinja to template the access token.
plugin: community.general.linode
access_token: "{{ lookup('ini', 'token', section='your_username', file='~/.config/linode-cli') }}"
# For older Ansible versions, you need to write this as:
# access_token: "{{ lookup('ini', 'token section=your_username file=~/.config/linode-cli') }}"

# Example with regions, types, groups and access token
plugin: community.general.linode
access_token: foobar
regions:
  - eu-west
types:
  - g5-standard-2

# Example with keyed_groups, groups, and compose
plugin: community.general.linode
access_token: foobar
keyed_groups:
  - key: tags
    separator: ''
  - key: region
    prefix: region
groups:
  webservers: "'web' in (tags|list)"
  mailservers: "'mail' in (tags|list)"
compose:
  # By default, Ansible tries to connect to the label of the instance.
  # Since that might not be a valid name to connect to, you can
  # replace it with the first IPv4 address of the linode as follows:
  ansible_ssh_host: ipv4[0]
  ansible_port: 2222

# Example where control traffic limited to internal network
plugin: community.general.linode
access_token: foobar
ip_style: api
compose:
  ansible_host: "ipv4 | community.general.json_query('[?public==`false`].address') | first"

作者

  • Luke Murphy (@decentral1se)

提示

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