|
|
@ -34,30 +34,34 @@ DOCUMENTATION = '''
|
|
|
|
type: list
|
|
|
|
type: list
|
|
|
|
elements: string
|
|
|
|
elements: string
|
|
|
|
required: True
|
|
|
|
required: True
|
|
|
|
_etcd_url:
|
|
|
|
url:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Environment variable with the url for the etcd server
|
|
|
|
- Environment variable with the url for the etcd server
|
|
|
|
default: 'http://127.0.0.1:4001'
|
|
|
|
default: 'http://127.0.0.1:4001'
|
|
|
|
env:
|
|
|
|
env:
|
|
|
|
- name: ANSIBLE_ETCD_URL
|
|
|
|
- name: ANSIBLE_ETCD_URL
|
|
|
|
yaml:
|
|
|
|
version:
|
|
|
|
- key: etcd.url
|
|
|
|
|
|
|
|
_etcd_version:
|
|
|
|
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Environment variable with the etcd protocol version
|
|
|
|
- Environment variable with the etcd protocol version
|
|
|
|
default: 'v1'
|
|
|
|
default: 'v1'
|
|
|
|
env:
|
|
|
|
env:
|
|
|
|
- name: ANSIBLE_ETCD_VERSION
|
|
|
|
- name: ANSIBLE_ETCD_VERSION
|
|
|
|
yaml:
|
|
|
|
validate_certs:
|
|
|
|
- key: etcd.version
|
|
|
|
description:
|
|
|
|
|
|
|
|
- toggle checking that the ssl ceritificates are valid, you normally only want to turn this off with self-signed certs.
|
|
|
|
|
|
|
|
default: True
|
|
|
|
|
|
|
|
type: boolean
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
|
|
|
EXAMPLES = '''
|
|
|
|
- name: "a value from a locally running etcd"
|
|
|
|
- name: "a value from a locally running etcd"
|
|
|
|
debug: msg={{ lookup('etcd', 'foo/bar') }}
|
|
|
|
debug: msg={{ lookup('etcd', 'foo/bar') }}
|
|
|
|
|
|
|
|
|
|
|
|
- name: "a values from a folder on a locally running etcd"
|
|
|
|
- name: "values from multiple folders on a locally running etcd"
|
|
|
|
debug: msg={{ lookup('etcd', 'foo') }}
|
|
|
|
debug: msg={{ lookup('etcd', 'foo', 'bar', 'baz') }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: "since Ansible 2.5 you can set server options inline"
|
|
|
|
|
|
|
|
debug: msg="{{ lookup('etcd', 'foo', version='v2', url='http://192.168.0.27:4001') }}"
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
RETURN = '''
|
|
|
|
RETURN = '''
|
|
|
@ -68,12 +72,7 @@ RETURN = '''
|
|
|
|
elements: strings
|
|
|
|
elements: strings
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
|
|
import simplejson as json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from ansible.plugins.lookup import LookupBase
|
|
|
|
from ansible.plugins.lookup import LookupBase
|
|
|
|
from ansible.module_utils.urls import open_url
|
|
|
|
from ansible.module_utils.urls import open_url
|
|
|
@ -102,18 +101,10 @@ from ansible.module_utils.urls import open_url
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
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']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ANSIBLE_ETCD_VERSION = 'v1'
|
|
|
|
|
|
|
|
if os.getenv('ANSIBLE_ETCD_VERSION') is not None:
|
|
|
|
|
|
|
|
ANSIBLE_ETCD_VERSION = os.environ['ANSIBLE_ETCD_VERSION']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Etcd:
|
|
|
|
class Etcd:
|
|
|
|
def __init__(self, url=ANSIBLE_ETCD_URL, version=ANSIBLE_ETCD_VERSION,
|
|
|
|
def __init__(self, url, version, validate_certs):
|
|
|
|
validate_certs=True):
|
|
|
|
|
|
|
|
self.url = url
|
|
|
|
self.url = url
|
|
|
|
self.version = version
|
|
|
|
self.version = version
|
|
|
|
self.baseurl = '%s/%s/keys' % (self.url, self.version)
|
|
|
|
self.baseurl = '%s/%s/keys' % (self.url, self.version)
|
|
|
@ -143,7 +134,7 @@ class Etcd:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
r = open_url(url, validate_certs=self.validate_certs)
|
|
|
|
r = open_url(url, validate_certs=self.validate_certs)
|
|
|
|
data = r.read()
|
|
|
|
data = r.read()
|
|
|
|
except:
|
|
|
|
except Exception:
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -161,7 +152,7 @@ class Etcd:
|
|
|
|
if 'errorCode' in item:
|
|
|
|
if 'errorCode' in item:
|
|
|
|
# Here return an error when an unknown entry responds
|
|
|
|
# Here return an error when an unknown entry responds
|
|
|
|
value = "ENOENT"
|
|
|
|
value = "ENOENT"
|
|
|
|
except:
|
|
|
|
except Exception:
|
|
|
|
raise
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
return value
|
|
|
|
return value
|
|
|
@ -171,9 +162,11 @@ class LookupModule(LookupBase):
|
|
|
|
|
|
|
|
|
|
|
|
def run(self, terms, variables, **kwargs):
|
|
|
|
def run(self, terms, variables, **kwargs):
|
|
|
|
|
|
|
|
|
|
|
|
validate_certs = kwargs.get('validate_certs', True)
|
|
|
|
self.set_options(var_options=variables, direct=kwargs)
|
|
|
|
url = kwargs.get('url', '')
|
|
|
|
|
|
|
|
version = kwargs.get('version', '')
|
|
|
|
validate_certs = self._options['validate_certs']
|
|
|
|
|
|
|
|
url = self._options['url']
|
|
|
|
|
|
|
|
version = self._options['version']
|
|
|
|
|
|
|
|
|
|
|
|
etcd = Etcd(url=url, version=version, validate_certs=validate_certs)
|
|
|
|
etcd = Etcd(url=url, version=version, validate_certs=validate_certs)
|
|
|
|
|
|
|
|
|
|
|
|