diff --git a/lib/ansible/plugins/lookup/etcd.py b/lib/ansible/plugins/lookup/etcd.py index 6530c0e283d..4ed7db24da6 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: