community.general.consul_session 模块 – 操作 Consul 会话

注意

此模块是 community.general 集合(版本 10.1.0)的一部分。

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

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

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

概要

参数

参数

注释

behavior

字符串

创建会话时可以附加的可选行为。这控制会话失效时的行为。

选项

  • "delete"

  • "release" ← (默认)

ca_path

字符串

用于 https 连接的 CA 捆绑包

checks

列表 / 元素=字符串

用于验证会话运行状况的检查。如果所有检查都失败,则会话将失效,并且与该会话关联的任何锁都将被释放,并且可以在关联的锁延迟过期后获取。

datacenter

字符串

会话存在或应该创建的数据中心的名称。

delay

整数

创建会话时可以附加的可选锁定延迟。失效会话的锁在延迟过期之前被阻止获取。持续时间以秒为单位。

默认值: 15

host

字符串

Consul 代理的主机,默认为 localhost

默认值: "localhost"

id

字符串

会话的 ID,当 stateinforemove 时是必需的。

name

字符串

应与会话关联的名称。当使用 state=node 时是必需的。

node

字符串

会话将与之关联的节点的名称。默认情况下,这是代理的名称。

port

整数

Consul 代理正在运行的端口。

默认值: 8500

scheme

字符串

Consul 代理正在运行的协议方案。默认为 http,对于安全连接,可以设置为 https

默认值: "http"

state

字符串

会话应该存在(即如果不存在则创建),还是不存在(如果存在则删除)。如果创建,则会话的 id 将在输出中返回。如果为 absent,则需要 id 来删除会话。可以通过为 state 指定 infonodelist 来检索单个会话的信息、节点的所有会话或所有可用会话;对于 nodeinfo,需要将节点 name 或会话 id 作为参数。

选项

  • "absent"(不存在)

  • "info"(信息)

  • "list"(列表)

  • "node"(节点)

  • "present" ← (默认)

token(令牌)

字符串

在 community.general 5.6.0 中添加

用于授权的令牌。

ttl

整数

在 community.general 5.4.0 中添加

指定会话的持续时间(以秒为单位,介于 10 到 86400 之间)。

validate_certs

boolean(布尔值)

是否验证 consul 代理的 TLS 证书。

选项

  • false(假)

  • true ← (默认)

属性

属性

支持

描述

action_group

操作组: community.general.consul

在 community.general 8.3.0 中添加

module_defaults 中使用 group/community.general.consul 来为此模块设置默认值。

check_mode

支持:

可以在 check_mode 中运行,并返回更改状态预测,而不修改目标。

diff_mode

支持:

在 diff 模式下,将返回已更改的内容的详细信息(或可能需要在 check_mode 中更改的内容)。

示例

- name: Register basic session with consul
  community.general.consul_session:
    name: session1

- name: Register a session with an existing check
  community.general.consul_session:
    name: session_with_check
    checks:
      - existing_check_name

- name: Register a session with lock_delay
  community.general.consul_session:
    name: session_with_delay
    delay: 20s

- name: Retrieve info about session by id
  community.general.consul_session:
    id: session_id
    state: info

- name: Retrieve active sessions
  community.general.consul_session:
    state: list

- name: Register session with a ttl
  community.general.consul_session:
    name: session-with-ttl
    ttl: 600  # sec

作者

  • Steve Gargan (@sgargan)

  • Håkon Lerring (@Hakon)