community.general.consul_session (8.5.0) — module

Manipulate consul sessions

Authors: Steve Gargan (@sgargan), Håkon Lerring (@Hakon)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Allows the addition, modification and deletion of sessions in a consul cluster. These sessions can then be used in conjunction with key value pairs to implement distributed locks. In depth documentation for working with sessions can be found at http://www.consul.io/docs/internals/sessions.html

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Register basic session with consul
  community.general.consul_session:
    name: session1
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Register a session with an existing check
  community.general.consul_session:
    name: session_with_check
    checks:
      - existing_check_name
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Register a session with lock_delay
  community.general.consul_session:
    name: session_with_delay
    delay: 20s
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Retrieve info about session by id
  community.general.consul_session:
    id: session_id
    state: info
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Retrieve active sessions
  community.general.consul_session:
    state: list
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Register session with a ttl
  community.general.consul_session:
    name: session-with-ttl
    ttl: 600  # sec

Inputs

    
id:
    description:
    - ID of the session, required when O(state) is either V(info) or V(remove).
    type: str

ttl:
    description:
    - Specifies the duration of a session in seconds (between 10 and 86400).
    type: int
    version_added: 5.4.0
    version_added_collection: community.general

host:
    default: localhost
    description:
    - Host of the consul agent, defaults to V(localhost).
    type: str

name:
    description:
    - The name that should be associated with the session. Required when O(state=node)
      is used.
    type: str

node:
    description:
    - The name of the node that with which the session will be associated. by default
      this is the name of the agent.
    type: str

port:
    default: 8500
    description:
    - The port on which the consul agent is running.
    type: int

delay:
    default: 15
    description:
    - The optional lock delay that can be attached to the session when it is created.
      Locks for invalidated sessions ar blocked from being acquired until this delay has
      expired. Durations are in seconds.
    type: int

state:
    choices:
    - absent
    - info
    - list
    - node
    - present
    default: present
    description:
    - Whether the session should be present i.e. created if it doesn't exist, or absent,
      removed if present. If created, the O(id) for the session is returned in the output.
      If V(absent), O(id) is required to remove the session. Info for a single session,
      all the sessions for a node or all available sessions can be retrieved by specifying
      V(info), V(node) or V(list) for the O(state); for V(node) or V(info), the node O(name)
      or session O(id) is required as parameter.
    type: str

token:
    description:
    - The token to use for authorization.
    type: str
    version_added: 5.6.0
    version_added_collection: community.general

checks:
    description:
    - Checks that will be used to verify the session health. If all the checks fail, the
      session will be invalidated and any locks associated with the session will be release
      and can be acquired once the associated lock delay has expired.
    elements: str
    type: list

scheme:
    default: http
    description:
    - The protocol scheme on which the consul agent is running. Defaults to V(http) and
      can be set to V(https) for secure connections.
    type: str

ca_path:
    description:
    - The CA bundle to use for https connections
    type: str

behavior:
    choices:
    - delete
    - release
    default: release
    description:
    - The optional behavior that can be attached to the session when it is created. This
      controls the behavior when a session is invalidated.
    type: str

datacenter:
    description:
    - The name of the datacenter in which the session exists or should be created.
    type: str

validate_certs:
    default: true
    description:
    - Whether to verify the TLS certificate of the consul agent.
    type: bool