community.general.consul_kv module – Manipulate entries in the key/value store of a consul cluster
Note
This module is part of the community.general collection (version 10.0.1).
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
.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: community.general.consul_kv
.
Synopsis
Allows the retrieval, addition, modification and deletion of key/value entries in a consul cluster via the agent. The entire contents of the record, including the indices, flags and session are returned as
value
.If the
key
represents a prefix then note that when a value is removed, the existing value if any is returned as part of the results.See http://www.consul.io/docs/agent/http.html#kv for more details.
Requirements
The below requirements are needed on the host that executes this module.
python-consul
requests
Parameters
Parameter |
Comments |
---|---|
The name of the datacenter to query. If unspecified, the query will default to the datacenter of the Consul agent on |
|
Opaque positive integer value that can be passed when setting a value. |
|
Host of the consul agent. Default: |
|
The key at which the value should be stored. |
|
The port on which the consul agent is running. Default: |
|
If the key represents a prefix, each entry with the prefix can be retrieved by setting this to Choices:
|
|
The protocol scheme on which the consul agent is running. Default: |
|
The session that should be used to acquire or release a lock associated with a key/value pair. |
|
The action to take with the supplied key and value. If the state is Choices:
|
|
The token key identifying an ACL rule set that controls access to the key value pair |
|
Whether to verify the tls certificate of the consul agent. Choices:
|
|
The value should be associated with the given key, required if |
Attributes
Attribute |
Support |
Description |
---|---|---|
Support: full |
Can run in |
|
Support: none |
Will return details on what has changed (or possibly needs changing in |
Examples
# If the key does not exist, the value associated to the "data" property in `retrieved_key` will be `None`
# If the key value is empty string, `retrieved_key["data"]["Value"]` will be `None`
- name: Retrieve a value from the key/value store
community.general.consul_kv:
key: somekey
register: retrieved_key
- name: Add or update the value associated with a key in the key/value store
community.general.consul_kv:
key: somekey
value: somevalue
- name: Remove a key from the store
community.general.consul_kv:
key: somekey
state: absent
- name: Add a node to an arbitrary group via consul inventory (see consul.ini)
community.general.consul_kv:
key: ansible/groups/dc1/somenode
value: top_secret
- name: Register a key/value pair with an associated session
community.general.consul_kv:
key: stg/node/server_birthday
value: 20160509
session: "{{ sessionid }}"
state: acquire