ansible.builtin.consul_kv (v2.9.27) — lookup

Fetch metadata from a Consul key value store.

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

Authors: unknown

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.9.27

Description

Lookup metadata for a playbook from the key value store in a Consul cluster. Values can be easily set in the kv store with simple rest commands

C(curl -X PUT -d 'some-value' http://localhost:8500/v1/kv/ansible/somedata)


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
  - debug:
      msg: 'key contains {{item}}'
    with_consul_kv:
      - 'key/to/retrieve'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
  - name: Parameters can be provided after the key be more specific about what to retrieve
    debug:
      msg: 'key contains {{item}}'
    with_consul_kv:
      - 'key/to recurse=true token=E6C060A9-26FB-407A-B83E-12DDAFCB4D98'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
  - name: retrieving a KV from a remote cluster on non default port
    debug:
      msg: "{{ lookup('consul_kv', 'my/key', host='10.10.10.10', port='2000') }}"

Inputs

    
_raw:
    description: List of key(s) to retrieve.
    required: true
    type: list

host:
    default: localhost
    description:
    - The target to connect to, must be a resolvable address. Will be determined from
      C(ANSIBLE_CONSUL_URL) if that is set.
    - 'C(ANSIBLE_CONSUL_URL) should look like this: C(https://my.consul.server:8500)'
    env:
    - name: ANSIBLE_CONSUL_URL
    ini:
    - key: host
      section: lookup_consul
    version_added: '2.8'
    version_added_collection: ansible.builtin

port:
    default: 8500
    description:
    - The port of the target host to connect to.
    - If you use C(ANSIBLE_CONSUL_URL) this value will be used from there.

index:
    description:
    - If the key has a value with the specified index then this is returned allowing access
      to historical values.

token:
    description: The acl token to allow access to restricted values.

scheme:
    default: http
    description:
    - Whether to use http or https.
    - If you use C(ANSIBLE_CONSUL_URL) this value will be used from there.
    version_added: '2.8'
    version_added_collection: ansible.builtin

recurse:
    default: false
    description: If true, will retrieve all the values that have the given key as prefix.
    type: boolean

datacenter:
    description:
    - Retrieve the key from a consul datatacenter other than the default for the consul
      host.
    version_added: '2.9'
    version_added_collection: ansible.builtin

client_cert:
    description: The client cert to verify the ssl connection.
    env:
    - name: ANSIBLE_CONSUL_CLIENT_CERT
    ini:
    - key: client_cert
      section: lookup_consul
    version_added: '2.8'
    version_added_collection: ansible.builtin

validate_certs:
    default: true
    description: Whether to verify the ssl connection or not.
    env:
    - name: ANSIBLE_CONSUL_VALIDATE_CERTS
    ini:
    - key: validate_certs
      section: lookup_consul
    version_added: '2.8'
    version_added_collection: ansible.builtin

Outputs

_raw:
  description:
  - Value(s) stored in consul.