ansibleconsulconsul-kv

ansible the way to use consul_kv change between two versions


I need some help on using consul_kv module with ansible version since 2.8.x , maybe i missed something, but i took a look to the code of the module and i don't realy see changes between 2.7.x and 2.8.x that can explay the problem i got.

With ansible 2.7.x , when i try to get value from consul, i get consul host, port, path from my env vars and i execute my code like this:

# group_var/all
consul_path: "{{ lookup('env','ANSIBLE_CONSUL_PATH') }}"
consul_host: "{{ lookup('env','ANSIBLE_CONSUL_HOST') }}"
consul_port: "{{ lookup('env', 'ANSIBLE_CONSUL_PORT') }}"
- hosts: localhost

  tasks:
    - name: test ansible 2.8.5 with consul
      debug:
        msg: "{{ lookup('consul_kv', consul_path+'path/to/value' }}"

it works on 2.7.0 and i got my value, but doesn't work on 2.8.x , from those newer versions i need to specify host and port on each line which using lookup

msg: "{{ lookup('consul_kv', 'path/to/value', host='myconsulhost.com', port='80') }}"

Is there a way to continue to use env vars in ansible 2.8.x with this module ?


Solution

  • The fine manual says that the lookup now uses the $ANSIBLE_CONSUL_URL environment variable to determine the protocol, hostname, and port -- or (as you observed) using the inline kwargs to the lookup function. Those group_vars you mentioned no longer seem to be consulted

    You'll also want to be careful as your group_vars/all (at least in this question, unknown if you are really doing it) has a trailing space in consul_path : which creates a variable named consul_path<space>