Passing token to Consul via lookup plugin

185 views
Skip to first unread message

Samnang Sen

unread,
Aug 21, 2015, 3:52:00 PM8/21/15
to Ansible Project
How do I pass the token to Consul?

This doesn't appear to work, I'm not getting the value. However, if i set Consul to allow anonymous queries, it works fine.

{{ lookup('consul_kv',item,"token=mysecretoken") }}

Brian Coca

unread,
Aug 21, 2015, 4:05:24 PM8/21/15
to Ansible Project
The lookup currently does not seem to support auth, but it should not
be hard to modify to do so.


--
Brian Coca

Samnang Sen

unread,
Aug 21, 2015, 4:07:52 PM8/21/15
to Ansible Project
Well according to this file (is this the right one?) I see paramters for token.

/usr/lib/python2.7/site-packages/ansible/runner/lookup_plugins/consul_kv.py

results = consul_api.kv.get(params['key'],
                                            token=params['token'],
                                            index=params['index'],
                                            recurse=params['recurse'])

Brian Coca

unread,
Aug 21, 2015, 4:14:28 PM8/21/15
to Ansible Project
ah, yes, i missed that, i was looking at the env variables

self.agent_url = 'http://localhost:8500'
if os.getenv('ANSIBLE_CONSUL_URL') is not None:
self.agent_url = os.environ['ANSIBLE_CONSUL_URL']

do you get any errors when trying to use the token?

--
Brian Coca

Matt Martz

unread,
Aug 21, 2015, 4:16:53 PM8/21/15
to ansible...@googlegroups.com
I think the problem is in that the entire kwarg is quoted in your example:

{{ lookup('consul_kv',item,"token=mysecretoken") }}

It should probably be:

{{ lookup('consul_kv', item, token="mysecretoken") }}

Just quote the value, not the arg name.


--
Brian Coca

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAJ5XC8%3D1SpYtv1%3DmNVxg_GVcaNR9XtCoGGCHpA44UPWQMZxobA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

Samnang Sen

unread,
Aug 21, 2015, 4:27:22 PM8/21/15
to Ansible Project
I've tried that as well. I don't think it works because I used the following and it did not throw an error. Notice, I used "token123" and it didn't error out at all.
 
{{ lookup('consul_kv', item, token123="mysecretoken") }}
Reply all
Reply to author
Forward
0 new messages