community.general.proxmox inventory – Proxmox 清单源

注意

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

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

要安装它,请使用:ansible-galaxy collection install community.general。您需要进一步的要求才能使用此清单插件,有关详细信息,请参阅要求

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

community.general 1.2.0 中的新增功能

概要

  • 从 Proxmox PVE 集群获取清单主机。

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

  • 将检索 Proxmox 节点的第一个具有 IP 的网络接口。

  • 可以将 LXC/QEMU 配置作为事实检索。

要求

以下要求需要在执行此清单的本地控制器节点上满足。

  • requests >= 1.1

参数

参数

注释

cache

布尔值

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

选择

  • false ←(默认)

  • true

配置

cache_connection

字符串

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

配置

cache_plugin

字符串

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

默认值: "memory"

配置

cache_prefix

字符串

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

默认值: "ansible_inventory_"

配置

cache_timeout

整数

缓存持续时间(秒)。

默认值: 3600

配置

compose

字典

在 community.general 2.5.0 中添加

从 jinja2 表达式创建变量。

默认值: {}

exclude_nodes

布尔值

在 community.general 8.1.0 中添加

从清单输出中排除 proxmox 节点和 nodes-group。

选择

  • false ←(默认)

  • true

facts_prefix

字符串

应用于 LXC/QEMU 配置事实的前缀。

默认值: "proxmox_"

filters

列表 / 元素=字符串

在 community.general 4.6.0 中添加

允许过滤主机的一系列 Jinja 模板。

默认值: []

group_prefix

字符串

应用于 Proxmox 组的前缀。

默认值: "proxmox_"

groups

字典

在 community.general 2.5.0 中添加

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

默认值: {}

keyed_groups

列表 / 元素=字典

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

password

字符串

Proxmox 身份验证密码。

如果未在清单配置中指定该值,则将使用环境变量 PROXMOX_PASSWORD 的值。

自 community.general 4.7.0 起,您还可以使用模板来指定 password 的值。

如果未指定密码,则必须设置 token_idtoken_secret

配置

plugin

字符串 / 必需

此插件的名称,应始终设置为 community.general.proxmox,以便此插件将其识别为自身。

选择

  • "community.general.proxmox"

qemu_extended_statuses

布尔值

在 community.general 5.1.0 中添加

需要将 want_facts 设置为 true 才能起作用。这将允许您区分 QEMU VM 的 pausedprelaunch 状态。

这将引入多个组 [前缀为 group_prefix] prelaunchpaused

选择

  • false ←(默认)

  • true

strict

布尔值

在 community.general 2.5.0 中添加

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

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

选择

  • false ←(默认)

  • true

token_id

字符串

在 community.general 4.8.0 中添加

Proxmox 身份验证令牌 ID。

如果未在清单配置中指定该值,则将使用环境变量 PROXMOX_TOKEN_ID 的值。

要使用令牌身份验证,您还必须指定 token_secret。如果未指定 token_idtoken_secret,则必须改为设置密码。

确保授予令牌显式的 pve 权限,或者禁用“特权隔离”以改为使用用户的特权。

配置

token_secret

字符串

在 community.general 4.8.0 中添加

Proxmox 身份验证令牌密钥。

如果未在清单配置中指定该值,则将使用环境变量 PROXMOX_TOKEN_SECRET 的值。

要使用令牌身份验证,您还必须指定 token_id。如果未指定 token_idtoken_secret,则必须改为设置密码。

配置

url

字符串

Proxmox 集群的 URL。

如果未在清单配置中指定该值,则将使用环境变量 PROXMOX_URL 的值。

自 community.general 4.7.0 起,您还可以使用模板来指定 url 的值。

默认值: "https://127.0.0.1:8006"

配置

  • 环境变量: PROXMOX_URL

    在 community.general 2.0.0 中添加

use_extra_vars

布尔值

在 ansible-core 2.11 中添加

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

选择

  • false ←(默认)

  • true

配置

user

字符串 / 必需

Proxmox 身份验证用户。

如果未在清单配置中指定该值,则将使用环境变量 PROXMOX_USER 的值。

自 community.general 4.7.0 起,您还可以使用模板来指定 user 的值。

配置

  • 环境变量: PROXMOX_USER

    在 community.general 2.0.0 中添加

validate_certs

布尔值

如果使用 HTTPS,则验证 SSL 证书。

选择

  • false

  • true ← (默认)

want_facts

布尔值

收集 LXC/QEMU 配置信息。

want_facts 设置为 true 时,可以获得有关 QEMU VM 状态的更多详细信息,除了运行和停止状态之外。目前,如果 VM 正在运行并且已挂起,则状态将为正在运行,并且计算机将位于 running 组中,但其实际状态将为暂停。请参阅 qemu_extended_statuses 以了解如何检索真实状态。

选择

  • false ←(默认)

  • true

want_proxmox_nodes_ansible_host

布尔值

在 community.general 3.0.0 中添加

是否为 proxmox 节点设置 ansible_host

设置为 true (默认值)时,将使用第一个可用的接口。这可能与您预期的不同。

此选项的默认值在 community.general 6.0.0 中从 true 更改为 false

选择

  • false ←(默认)

  • true

示例

# Minimal example which will not gather additional facts for QEMU/LXC guests
# By not specifying a URL the plugin will attempt to connect to the controller host on port 8006
# my.proxmox.yml
plugin: community.general.proxmox
user: ansible@pve
password: secure
# Note that this can easily give you wrong values as ansible_host. See further below for
# an example where this is set to `false` and where ansible_host is set with `compose`.
want_proxmox_nodes_ansible_host: true

# Instead of login with password, proxmox supports api token authentication since release 6.2.
plugin: community.general.proxmox
user: ci@pve
token_id: gitlab-1
token_secret: fa256e9c-26ab-41ec-82da-707a2c079829

# The secret can also be a vault string or passed via the environment variable TOKEN_SECRET.
token_secret: !vault |
          $ANSIBLE_VAULT;1.1;AES256
          62353634333163633336343265623632626339313032653563653165313262343931643431656138
          6134333736323265656466646539663134306166666237630a653363623262636663333762316136
          34616361326263383766366663393837626437316462313332663736623066656237386531663731
          3037646432383064630a663165303564623338666131353366373630656661333437393937343331
          32643131386134396336623736393634373936356332623632306561356361323737313663633633
          6231313333666361656537343562333337323030623732323833

# More complete example demonstrating the use of 'want_facts' and the constructed options
# Note that using facts returned by 'want_facts' in constructed options requires 'want_facts=true'
# my.proxmox.yml
plugin: community.general.proxmox
url: http://pve.domain.com:8006
user: ansible@pve
password: secure
want_facts: true
keyed_groups:
    # proxmox_tags_parsed is an example of a fact only returned when 'want_facts=true'
  - key: proxmox_tags_parsed
    separator: ""
    prefix: group
groups:
  webservers: "'web' in (proxmox_tags_parsed|list)"
  mailservers: "'mail' in (proxmox_tags_parsed|list)"
compose:
  ansible_port: 2222
# Note that this can easily give you wrong values as ansible_host. See further below for
# an example where this is set to `false` and where ansible_host is set with `compose`.
want_proxmox_nodes_ansible_host: true

# Using the inventory to allow ansible to connect via the first IP address of the VM / Container
# (Default is connection by name of QEMU/LXC guests)
# Note: my_inv_var demonstrates how to add a string variable to every host used by the inventory.
# my.proxmox.yml
plugin: community.general.proxmox
url: http://192.168.1.2:8006
user: ansible@pve
password: secure
validate_certs: false  # only do this when you trust the network!
want_facts: true
want_proxmox_nodes_ansible_host: false
compose:
  ansible_host: proxmox_ipconfig0.ip | default(proxmox_net0.ip) | ipaddr('address')
  my_inv_var_1: "'my_var1_value'"
  my_inv_var_2: >
    "my_var_2_value"

# Specify the url, user and password using templating
# my.proxmox.yml
plugin: community.general.proxmox
url: "{{ lookup('ansible.builtin.ini', 'url', section='proxmox', file='file.ini') }}"
user: "{{ lookup('ansible.builtin.env','PM_USER') | default('ansible@pve') }}"
password: "{{ lookup('community.general.random_string', base64=True) }}"
# Note that this can easily give you wrong values as ansible_host. See further up for
# an example where this is set to `false` and where ansible_host is set with `compose`.
want_proxmox_nodes_ansible_host: true

作者

  • Jeffrey van Pelt (@Thulium-Drake)

提示

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