community.general.consul_kv_info module – Retrieve entries from the key/value store of a Consul cluster

Note

This module is part of the community.general collection (version 13.3.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general.

To use it in a playbook, specify: community.general.consul_kv_info.

New in community.general 13.3.0

Synopsis

Parameters

Parameter

Comments

ca_path

string

The CA bundle to use for https connections.

datacenter

string

The name of the datacenter to query. If unspecified, the query defaults to the datacenter of the Consul agent on host.

host

string

Host of the Consul agent.

Default: "localhost"

key

string / required

The key to retrieve.

When recurse is true, this is treated as a prefix.

port

integer

The port on which the consul agent is running.

Default: 8500

recurse

boolean

If true, retrieve all entries sharing the prefix specified by key.

Choices:

  • false ← (default)

  • true

scheme

string

The protocol scheme on which the Consul agent is running. Defaults to http and can be set to https for secure connections.

Default: "http"

token

string

The token to use for authorization.

validate_certs

boolean

Whether to verify the TLS certificate of the Consul agent.

Choices:

  • false

  • true ← (default)

Attributes

Attribute

Support

Description

action_group

Action group: community.general.consul

Use group/community.general.consul in module_defaults to set defaults for this module.

check_mode

Support: full

This action does not modify state.

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: N/A

This action does not modify state.

Returns details on what has changed (or possibly needs changing in check_mode), when in diff mode.

Examples

- name: Retrieve a single key
  community.general.consul_kv_info:
    key: somekey
  register: result

- name: Display the value
  ansible.builtin.debug:
    msg: "{{ result.data }}"

- name: Retrieve all keys under a prefix
  community.general.consul_kv_info:
    key: app/config/
    recurse: true
  register: result

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

data

list / elements=dictionary

The list of KV entries matching the query.

Each element is a dictionary with the keys Key, Value, Flags, and others returned by the Consul API.

The list is empty if the key does not exist.

Returned: always

index

string

The Consul index value from the X-Consul-Index response header.

Returned: always

Authors

  • Shreyash Bhosale (@Shreyashxredhat)