ansible.builtin.consul_kv (v2.5.11) — module

Manipulate entries in the key/value store of a consul cluster

| "added in version" 2.0 of ansible.builtin"

Authors: Steve Gargan (@sgargan), Colin Nolan (@colin-nolan)

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.5.11

Description

Allows the 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

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Add or update the value associated with a key in the key/value store
  consul_kv:
    key: somekey
    value: somevalue
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove a key from the store
  consul_kv:
    key: somekey
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Add a node to an arbitrary group via consul inventory (see consul.ini)
  consul_kv:
    key: ansible/groups/dc1/somenode
    value: top_secret
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Register a key/value pair with an associated session
  consul_kv:
    key: stg/node/server_birthday
    value: 20160509
    session: "{{ sessionid }}"
    state: acquire

Inputs

    
cas:
    description:
    - Used when acquiring a lock with a session. If the C(cas) is C(0), then Consul will
      only put the key if it does not already exist. If the C(cas) value is non-zero,
      then the key is only set if the index matches the ModifyIndex of that key.

key:
    description:
    - The key at which the value should be stored.
    required: true

host:
    default: localhost
    description:
    - Host of the consul agent.

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

flags:
    description:
    - Opaque integer value that can be passed when setting a value.

state:
    choices:
    - absent
    - acquire
    - present
    - release
    default: present
    description:
    - The action to take with the supplied key and value. If the state is 'present', the
      key contents will be set to the value supplied, 'changed' will be set to true only
      if the value was different to the current contents. The state 'absent' will remove
      the key/value pair, again 'changed' will be set to true only if the key actually
      existed prior to the removal. An attempt can be made to obtain or free the lock
      associated with a key/value pair with the states 'acquire' or 'release' respectively.
      a valid session must be supplied to make the attempt changed will be true if the
      attempt is successful, false otherwise.

token:
    description:
    - The token key indentifying an ACL rule set that controls access to the key value
      pair

value:
    description:
    - The value should be associated with the given key, required if C(state) is C(present).
    required: true

scheme:
    default: http
    description:
    - The protocol scheme on which the consul agent is running.
    version_added: '2.1'
    version_added_collection: ansible.builtin

recurse:
    default: 'no'
    description:
    - If the key represents a prefix, each entry with the prefix can be retrieved by setting
      this to C(yes).
    type: bool

session:
    description:
    - The session that should be used to acquire or release a lock associated with a key/value
      pair.

validate_certs:
    default: 'yes'
    description:
    - Whether to verify the tls certificate of the consul agent.
    type: bool
    version_added: '2.1'
    version_added_collection: ansible.builtin