etcd.py module improved . added posibility to configure from playbook… (#18580)

* 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.
This commit is contained in:
Mihai Moldovanu 2017-10-12 17:55:59 +03:00 committed by John R Barker
parent 4034630625
commit 79f2cfbcf9

View file

@ -1,4 +1,5 @@
# (c) 2013, Jan-Piet Mens <jpmens(at)gmail.com>
# (m) 2016, Mihai Moldovanu <mihaim@tfm.ro>
# (m) 2017, Juan Manuel Parrilla <jparrill@redhat.com>
#
# 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: