From 79f2cfbcf90ce4174b19b0093cd7ca8e57668c63 Mon Sep 17 00:00:00 2001 From: Mihai Moldovanu Date: Thu, 12 Oct 2017 17:55:59 +0300 Subject: [PATCH] =?UTF-8?q?etcd.py=20module=20improved=20.=20added=20posib?= =?UTF-8?q?ility=20to=20configure=20from=20playbook=E2=80=A6=20(#18580)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * etcd.py module improved . added posibility to configure from playbook etcd server to query * Update playbooks_lookups.rst documented etcd lookups * Update playbooks_lookups.rst * Update playbooks_lookups.rst * Update playbooks_lookups.rst * Update playbooks_lookups.rst * Update playbooks_lookups.rst * Fixed errors reported by ansibot * Update playbooks_lookups.rst * Update playbooks_lookups.rst * Copy edits. --- lib/ansible/plugins/lookup/etcd.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/lookup/etcd.py b/lib/ansible/plugins/lookup/etcd.py index 6530c0e283..4ed7db24da 100644 --- a/lib/ansible/plugins/lookup/etcd.py +++ b/lib/ansible/plugins/lookup/etcd.py @@ -1,4 +1,5 @@ # (c) 2013, Jan-Piet Mens +# (m) 2016, Mihai Moldovanu # (m) 2017, Juan Manuel Parrilla # # This file is part of Ansible @@ -78,6 +79,29 @@ from ansible.plugins.lookup import LookupBase from ansible.module_utils.urls import open_url # this can be made configurable, not should not use ansible.cfg +# +# Made module configurable from playbooks: +# If etcd v2 running on host 192.168.1.21 on port 2379 +# we can use the following in a playbook to retrieve /tfm/network/config key +# +# - debug: msg={{lookup('etcd','/tfm/network/config', url='http://192.168.1.21:2379' , version='v2')}} +# +# Example Output: +# +# TASK [debug] ******************************************************************* +# ok: [localhost] => { +# "msg": { +# "Backend": { +# "Type": "vxlan" +# }, +# "Network": "172.30.0.0/16", +# "SubnetLen": 24 +# } +# } +# +# +# +# ANSIBLE_ETCD_URL = 'http://127.0.0.1:4001' if os.getenv('ANSIBLE_ETCD_URL') is not None: ANSIBLE_ETCD_URL = os.environ['ANSIBLE_ETCD_URL'] @@ -148,8 +172,10 @@ class LookupModule(LookupBase): def run(self, terms, variables, **kwargs): validate_certs = kwargs.get('validate_certs', True) + url = kwargs.get('url', '') + version = kwargs.get('version', '') - etcd = Etcd(validate_certs=validate_certs) + etcd = Etcd(url=url, version=version, validate_certs=validate_certs) ret = [] for term in terms: