mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 22:30:22 -07:00
parent
2f33c1a1a1
commit
5553b20828
206 changed files with 1853 additions and 1870 deletions
|
@ -60,7 +60,7 @@ class LookupBase(with_metaclass(ABCMeta, object)):
|
|||
results = []
|
||||
for x in a:
|
||||
for y in b:
|
||||
results.append(LookupBase._flatten([x,y]))
|
||||
results.append(LookupBase._flatten([x, y]))
|
||||
return results
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -51,6 +51,7 @@ from ansible.errors import AnsibleError
|
|||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.utils.listify import listify_lookup_plugin_terms
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
"""
|
||||
Create the cartesian product of lists
|
||||
|
@ -79,4 +80,3 @@ class LookupModule(LookupBase):
|
|||
raise AnsibleError("with_cartesian requires at least one element in each list")
|
||||
|
||||
return [self._flatten(x) for x in product(*my_list)]
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ class CSVRecoder:
|
|||
def next(self):
|
||||
return self.reader.next().encode("utf-8")
|
||||
|
||||
|
||||
class CSVReader:
|
||||
"""
|
||||
A CSV reader which will iterate over lines in the CSV file "f",
|
||||
|
@ -56,6 +57,7 @@ class CSVReader:
|
|||
def __iter__(self):
|
||||
return self
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def read_csv(self, filename, key, delimiter, encoding='utf-8', dflt=None, col=1):
|
||||
|
@ -81,11 +83,11 @@ class LookupModule(LookupBase):
|
|||
key = params[0]
|
||||
|
||||
paramvals = {
|
||||
'col' : "1", # column to return
|
||||
'default' : None,
|
||||
'delimiter' : "TAB",
|
||||
'file' : 'ansible.csv',
|
||||
'encoding' : 'utf-8',
|
||||
'col': "1", # column to return
|
||||
'default': None,
|
||||
'delimiter': "TAB",
|
||||
'file': 'ansible.csv',
|
||||
'encoding': 'utf-8',
|
||||
}
|
||||
|
||||
# parameters specified?
|
||||
|
|
|
@ -22,6 +22,7 @@ import collections
|
|||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, variables=None, **kwargs):
|
||||
|
|
|
@ -29,11 +29,12 @@ try:
|
|||
import dns.reversename
|
||||
import dns.rdataclass
|
||||
from dns.rdatatype import (A, AAAA, CNAME, DLV, DNAME, DNSKEY, DS, HINFO, LOC,
|
||||
MX, NAPTR, NS, NSEC3PARAM, PTR, RP, SOA, SPF, SRV, SSHFP, TLSA, TXT)
|
||||
MX, NAPTR, NS, NSEC3PARAM, PTR, RP, SOA, SPF, SRV, SSHFP, TLSA, TXT)
|
||||
HAVE_DNS = True
|
||||
except ImportError:
|
||||
HAVE_DNS = False
|
||||
|
||||
|
||||
def make_rdata_dict(rdata):
|
||||
''' While the 'dig' lookup plugin supports anything which dnspython supports
|
||||
out of the box, the following supported_types list describes which
|
||||
|
@ -42,28 +43,28 @@ def make_rdata_dict(rdata):
|
|||
Note: adding support for RRSIG is hard work. :)
|
||||
'''
|
||||
supported_types = {
|
||||
A : ['address'],
|
||||
AAAA : ['address'],
|
||||
CNAME : ['target'],
|
||||
DNAME : ['target'],
|
||||
DLV : ['algorithm', 'digest_type', 'key_tag', 'digest'],
|
||||
DNSKEY : ['flags', 'algorithm', 'protocol', 'key'],
|
||||
DS : ['algorithm', 'digest_type', 'key_tag', 'digest'],
|
||||
HINFO : ['cpu', 'os'],
|
||||
LOC : ['latitude', 'longitude', 'altitude', 'size', 'horizontal_precision', 'vertical_precision'],
|
||||
MX : ['preference', 'exchange'],
|
||||
NAPTR : ['order', 'preference', 'flags', 'service', 'regexp', 'replacement'],
|
||||
NS : ['target'],
|
||||
NSEC3PARAM : ['algorithm', 'flags', 'iterations', 'salt'],
|
||||
PTR : ['target'],
|
||||
RP : ['mbox', 'txt'],
|
||||
# RRSIG : ['algorithm', 'labels', 'original_ttl', 'expiration', 'inception', 'signature'],
|
||||
SOA : ['mname', 'rname', 'serial', 'refresh', 'retry', 'expire', 'minimum'],
|
||||
SPF : ['strings'],
|
||||
SRV : ['priority', 'weight', 'port', 'target'],
|
||||
SSHFP : ['algorithm', 'fp_type', 'fingerprint'],
|
||||
TLSA : ['usage', 'selector', 'mtype', 'cert'],
|
||||
TXT : ['strings'],
|
||||
A: ['address'],
|
||||
AAAA: ['address'],
|
||||
CNAME: ['target'],
|
||||
DNAME: ['target'],
|
||||
DLV: ['algorithm', 'digest_type', 'key_tag', 'digest'],
|
||||
DNSKEY: ['flags', 'algorithm', 'protocol', 'key'],
|
||||
DS: ['algorithm', 'digest_type', 'key_tag', 'digest'],
|
||||
HINFO: ['cpu', 'os'],
|
||||
LOC: ['latitude', 'longitude', 'altitude', 'size', 'horizontal_precision', 'vertical_precision'],
|
||||
MX: ['preference', 'exchange'],
|
||||
NAPTR: ['order', 'preference', 'flags', 'service', 'regexp', 'replacement'],
|
||||
NS: ['target'],
|
||||
NSEC3PARAM: ['algorithm', 'flags', 'iterations', 'salt'],
|
||||
PTR: ['target'],
|
||||
RP: ['mbox', 'txt'],
|
||||
# RRSIG: ['algorithm', 'labels', 'original_ttl', 'expiration', 'inception', 'signature'],
|
||||
SOA: ['mname', 'rname', 'serial', 'refresh', 'retry', 'expire', 'minimum'],
|
||||
SPF: ['strings'],
|
||||
SRV: ['priority', 'weight', 'port', 'target'],
|
||||
SSHFP: ['algorithm', 'fp_type', 'fingerprint'],
|
||||
TLSA: ['usage', 'selector', 'mtype', 'cert'],
|
||||
TXT: ['strings'],
|
||||
}
|
||||
|
||||
rd = {}
|
||||
|
@ -71,7 +72,7 @@ def make_rdata_dict(rdata):
|
|||
if rdata.rdtype in supported_types:
|
||||
fields = supported_types[rdata.rdtype]
|
||||
for f in fields:
|
||||
val = rdata.__getattribute__(f)
|
||||
val = rdata.__getattribute__(f)
|
||||
|
||||
if isinstance(val, dns.name.Name):
|
||||
val = dns.name.Name.to_text(val)
|
||||
|
@ -89,11 +90,11 @@ def make_rdata_dict(rdata):
|
|||
if rdata.rdtype == TLSA and f == 'cert':
|
||||
val = dns.rdata._hexify(rdata.cert).replace(' ', '')
|
||||
|
||||
|
||||
rd[f] = val
|
||||
rd[f] = val
|
||||
|
||||
return rd
|
||||
|
||||
|
||||
# ==============================================================
|
||||
# dig: Lookup DNS records
|
||||
#
|
||||
|
@ -127,8 +128,8 @@ class LookupModule(LookupBase):
|
|||
myres.use_edns(0, ednsflags=dns.flags.DO, payload=edns_size)
|
||||
|
||||
domain = None
|
||||
qtype = 'A'
|
||||
flat = True
|
||||
qtype = 'A'
|
||||
flat = True
|
||||
rdclass = dns.rdataclass.from_text('IN')
|
||||
|
||||
for t in terms:
|
||||
|
@ -201,10 +202,10 @@ class LookupModule(LookupBase):
|
|||
else:
|
||||
try:
|
||||
rd = make_rdata_dict(rdata)
|
||||
rd['owner'] = answers.canonical_name.to_text()
|
||||
rd['type'] = dns.rdatatype.to_text(rdata.rdtype)
|
||||
rd['ttl'] = answers.rrset.ttl
|
||||
rd['class'] = dns.rdataclass.to_text(rdata.rdclass)
|
||||
rd['owner'] = answers.canonical_name.to_text()
|
||||
rd['type'] = dns.rdatatype.to_text(rdata.rdtype)
|
||||
rd['ttl'] = answers.rrset.ttl
|
||||
rd['class'] = dns.rdataclass.to_text(rdata.rdclass)
|
||||
|
||||
ret.append(rd)
|
||||
except Exception as e:
|
||||
|
|
|
@ -17,17 +17,18 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
HAVE_DNS=False
|
||||
HAVE_DNS = False
|
||||
try:
|
||||
import dns.resolver
|
||||
from dns.exception import DNSException
|
||||
HAVE_DNS=True
|
||||
HAVE_DNS = True
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
||||
# ==============================================================
|
||||
# DNSTXT: DNS TXT records
|
||||
|
@ -63,4 +64,3 @@ class LookupModule(LookupBase):
|
|||
ret.append(''.join(string))
|
||||
|
||||
return ret
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import os
|
|||
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
|
|
@ -74,12 +74,13 @@ ANSIBLE_ETCD_VERSION = 'v1'
|
|||
if os.getenv('ANSIBLE_ETCD_VERSION') is not None:
|
||||
ANSIBLE_ETCD_VERSION = os.environ['ANSIBLE_ETCD_VERSION']
|
||||
|
||||
|
||||
class Etcd:
|
||||
def __init__(self, url=ANSIBLE_ETCD_URL, version=ANSIBLE_ETCD_VERSION,
|
||||
validate_certs=True):
|
||||
self.url = url
|
||||
self.version = version
|
||||
self.baseurl = '%s/%s/keys' % (self.url,self.version)
|
||||
self.baseurl = '%s/%s/keys' % (self.url, self.version)
|
||||
self.validate_certs = validate_certs
|
||||
|
||||
def get(self, key):
|
||||
|
@ -111,6 +112,7 @@ class Etcd:
|
|||
|
||||
return value
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
|
|
@ -22,10 +22,10 @@ import pwd
|
|||
import grp
|
||||
import stat
|
||||
|
||||
HAVE_SELINUX=False
|
||||
HAVE_SELINUX = False
|
||||
try:
|
||||
import selinux
|
||||
HAVE_SELINUX=True
|
||||
HAVE_SELINUX = True
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
@ -38,6 +38,7 @@ except ImportError:
|
|||
from ansible.utils.display import Display
|
||||
display = Display()
|
||||
|
||||
|
||||
# If selinux fails to find a default, return an array of None
|
||||
def selinux_context(path):
|
||||
context = [None, None, None, None]
|
||||
|
@ -119,7 +120,7 @@ class LookupModule(LookupBase):
|
|||
relpath = os.path.relpath(os.path.join(root, entry), path)
|
||||
|
||||
# Skip if relpath was already processed (from another root)
|
||||
if relpath not in [ entry['path'] for entry in ret ]:
|
||||
if relpath not in [entry['path'] for entry in ret]:
|
||||
props = file_props(path, relpath)
|
||||
if props is not None:
|
||||
ret.append(props)
|
||||
|
|
|
@ -34,11 +34,11 @@ __metaclass__ = type
|
|||
# first file found with os.path.exists() is returned
|
||||
# no file matches raises ansibleerror
|
||||
# EXAMPLES
|
||||
# - name: copy first existing file found to /some/file
|
||||
# action: copy src=$item dest=/some/file
|
||||
# with_first_found:
|
||||
# - files: foo ${inventory_hostname} bar
|
||||
# paths: /tmp/production /tmp/staging
|
||||
# - name: copy first existing file found to /some/file
|
||||
# action: copy src=$item dest=/some/file
|
||||
# with_first_found:
|
||||
# - files: foo ${inventory_hostname} bar
|
||||
# paths: /tmp/production /tmp/staging
|
||||
|
||||
# that will look for files in this order:
|
||||
# /tmp/production/foo
|
||||
|
@ -48,10 +48,10 @@ __metaclass__ = type
|
|||
# ${inventory_hostname}
|
||||
# bar
|
||||
|
||||
# - name: copy first existing file found to /some/file
|
||||
# action: copy src=$item dest=/some/file
|
||||
# with_first_found:
|
||||
# - files: /some/place/foo ${inventory_hostname} /some/place/else
|
||||
# - name: copy first existing file found to /some/file
|
||||
# action: copy src=$item dest=/some/file
|
||||
# with_first_found:
|
||||
# - files: /some/place/foo ${inventory_hostname} /some/place/else
|
||||
|
||||
# that will look for files in this order:
|
||||
# /some/place/foo
|
||||
|
@ -59,47 +59,47 @@ __metaclass__ = type
|
|||
# /some/place/else
|
||||
|
||||
# example - including tasks:
|
||||
# tasks:
|
||||
# - include: $item
|
||||
# with_first_found:
|
||||
# - files: generic
|
||||
# paths: tasks/staging tasks/production
|
||||
# tasks:
|
||||
# - include: $item
|
||||
# with_first_found:
|
||||
# - files: generic
|
||||
# paths: tasks/staging tasks/production
|
||||
# this will include the tasks in the file generic where it is found first (staging or production)
|
||||
|
||||
# example simple file lists
|
||||
#tasks:
|
||||
#- name: first found file
|
||||
# action: copy src=$item dest=/etc/file.cfg
|
||||
# with_first_found:
|
||||
# - files: foo.${inventory_hostname} foo
|
||||
# tasks:
|
||||
# - name: first found file
|
||||
# action: copy src=$item dest=/etc/file.cfg
|
||||
# with_first_found:
|
||||
# - files: foo.${inventory_hostname} foo
|
||||
|
||||
|
||||
# example skipping if no matched files
|
||||
# First_found also offers the ability to control whether or not failing
|
||||
# to find a file returns an error or not
|
||||
#
|
||||
#- name: first found file - or skip
|
||||
# action: copy src=$item dest=/etc/file.cfg
|
||||
# with_first_found:
|
||||
# - files: foo.${inventory_hostname}
|
||||
# skip: true
|
||||
# - name: first found file - or skip
|
||||
# action: copy src=$item dest=/etc/file.cfg
|
||||
# with_first_found:
|
||||
# - files: foo.${inventory_hostname}
|
||||
# skip: true
|
||||
|
||||
# example a role with default configuration and configuration per host
|
||||
# you can set multiple terms with their own files and paths to look through.
|
||||
# consider a role that sets some configuration per host falling back on a default config.
|
||||
#
|
||||
#- name: some configuration template
|
||||
# template: src={{ item }} dest=/etc/file.cfg mode=0444 owner=root group=root
|
||||
# with_first_found:
|
||||
# - files:
|
||||
# - ${inventory_hostname}/etc/file.cfg
|
||||
# paths:
|
||||
# - ../../../templates.overwrites
|
||||
# - ../../../templates
|
||||
# - files:
|
||||
# - etc/file.cfg
|
||||
# paths:
|
||||
# - templates
|
||||
# - name: some configuration template
|
||||
# template: src={{ item }} dest=/etc/file.cfg mode=0444 owner=root group=root
|
||||
# with_first_found:
|
||||
# - files:
|
||||
# - ${inventory_hostname}/etc/file.cfg
|
||||
# paths:
|
||||
# - ../../../templates.overwrites
|
||||
# - ../../../templates
|
||||
# - files:
|
||||
# - etc/file.cfg
|
||||
# paths:
|
||||
# - templates
|
||||
|
||||
# the above will return an empty list if the files cannot be found at all
|
||||
# if skip is unspecificed or if it is set to false then it will return a list
|
||||
|
@ -110,13 +110,13 @@ __metaclass__ = type
|
|||
# first_available_file with with_first_found and leave the file listing in place
|
||||
#
|
||||
#
|
||||
# - name: with_first_found like first_available_file
|
||||
# action: copy src=$item dest=/tmp/faftest
|
||||
# with_first_found:
|
||||
# - ../files/foo
|
||||
# - ../files/bar
|
||||
# - ../files/baz
|
||||
# ignore_errors: true
|
||||
# - name: with_first_found like first_available_file
|
||||
# action: copy src=$item dest=/tmp/faftest
|
||||
# with_first_found:
|
||||
# - ../files/foo
|
||||
# - ../files/bar
|
||||
# - ../files/baz
|
||||
# ignore_errors: true
|
||||
|
||||
import os
|
||||
|
||||
|
@ -145,7 +145,7 @@ class LookupModule(LookupBase):
|
|||
if isinstance(term, dict):
|
||||
files = term.get('files', [])
|
||||
paths = term.get('paths', [])
|
||||
skip = boolean(term.get('skip', False))
|
||||
skip = boolean(term.get('skip', False))
|
||||
|
||||
filelist = files
|
||||
if isinstance(files, string_types):
|
||||
|
@ -191,4 +191,3 @@ class LookupModule(LookupBase):
|
|||
else:
|
||||
raise AnsibleLookupError("No file was found when using with_first_found. Use the 'skip: true' option to allow this task to be skipped if no "
|
||||
"files are found")
|
||||
|
||||
|
|
|
@ -29,9 +29,9 @@ class LookupModule(LookupBase):
|
|||
# make sure term is not a list of one (list of one..) item
|
||||
# return the final non list item if so
|
||||
|
||||
if isinstance(term,list) and len(term) == 1:
|
||||
if isinstance(term, list) and len(term) == 1:
|
||||
term = term[0]
|
||||
if isinstance(term,list):
|
||||
if isinstance(term, list):
|
||||
term = self._check_list_of_one_list(term)
|
||||
|
||||
return term
|
||||
|
@ -50,7 +50,7 @@ class LookupModule(LookupBase):
|
|||
# convert a variable to a list
|
||||
term2 = listify_lookup_plugin_terms(term, templar=self._templar, loader=self._loader)
|
||||
# but avoid converting a plain string to a list of one string
|
||||
if term2 != [ term ]:
|
||||
if term2 != [term]:
|
||||
term = term2
|
||||
|
||||
if isinstance(term, list):
|
||||
|
@ -62,11 +62,9 @@ class LookupModule(LookupBase):
|
|||
|
||||
return ret
|
||||
|
||||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
||||
if not isinstance(terms, list):
|
||||
raise AnsibleError("with_flattened expects a list")
|
||||
|
||||
return self._do_flatten(terms, variables)
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
# necessarily be an error if a bad endpoint is specified.
|
||||
#
|
||||
# Requires hvac library. Install with pip.
|
||||
#
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
@ -46,6 +45,7 @@ ANSIBLE_HASHI_VAULT_ADDR = 'http://127.0.0.1:8200'
|
|||
if os.getenv('VAULT_ADDR') is not None:
|
||||
ANSIBLE_HASHI_VAULT_ADDR = os.environ['VAULT_ADDR']
|
||||
|
||||
|
||||
class HashiVault:
|
||||
def __init__(self, **kwargs):
|
||||
try:
|
||||
|
@ -62,7 +62,7 @@ class HashiVault:
|
|||
|
||||
s_f = s.split(':')
|
||||
self.secret = s_f[0]
|
||||
if len(s_f)>=2:
|
||||
if len(s_f) >= 2:
|
||||
self.secret_field = s_f[1]
|
||||
else:
|
||||
self.secret_field = 'value'
|
||||
|
@ -108,7 +108,7 @@ class HashiVault:
|
|||
if data is None:
|
||||
raise AnsibleError("The secret %s doesn't seem to exist" % self.secret)
|
||||
|
||||
if self.secret_field=='': # secret was specified with trailing ':'
|
||||
if self.secret_field == '': # secret was specified with trailing ':'
|
||||
return data['data']
|
||||
|
||||
if self.secret_field not in data['data']:
|
||||
|
@ -153,4 +153,3 @@ class LookupModule(LookupBase):
|
|||
ret.append(value)
|
||||
|
||||
return ret
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ __metaclass__ = type
|
|||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def __init__(self, basedir=None, **kwargs):
|
||||
|
@ -32,4 +33,3 @@ class LookupModule(LookupBase):
|
|||
|
||||
items = self._flatten(terms)
|
||||
return list(zip(range(len(items)), items))
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ def _parse_params(term):
|
|||
params[k] = ''
|
||||
|
||||
thiskey = 'key'
|
||||
for idp,phrase in enumerate(term.split()):
|
||||
for idp, phrase in enumerate(term.split()):
|
||||
for k in keys:
|
||||
if ('%s=' % k) in phrase:
|
||||
thiskey = k
|
||||
|
@ -81,7 +81,7 @@ class LookupModule(LookupBase):
|
|||
|
||||
basedir = self.get_basedir(variables)
|
||||
self.basedir = basedir
|
||||
self.cp = configparser.ConfigParser()
|
||||
self.cp = configparser.ConfigParser()
|
||||
|
||||
ret = []
|
||||
for term in terms:
|
||||
|
@ -89,11 +89,11 @@ class LookupModule(LookupBase):
|
|||
key = params[0]
|
||||
|
||||
paramvals = {
|
||||
'file' : 'ansible.ini',
|
||||
're' : False,
|
||||
'default' : None,
|
||||
'section' : "global",
|
||||
'type' : "ini",
|
||||
'file': 'ansible.ini',
|
||||
're': False,
|
||||
'default': None,
|
||||
'section': "global",
|
||||
'type': "ini",
|
||||
}
|
||||
|
||||
# parameters specified?
|
||||
|
|
|
@ -19,14 +19,15 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.inventory.manager import split_host_pattern, order_patterns
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def get_hosts(self, variables, pattern):
|
||||
hosts = []
|
||||
if pattern[0] in ('!','&'):
|
||||
if pattern[0] in ('!', '&'):
|
||||
obj = pattern[1:]
|
||||
else:
|
||||
obj = pattern
|
||||
|
@ -47,9 +48,9 @@ class LookupModule(LookupBase):
|
|||
for p in patterns:
|
||||
that = self.get_hosts(variables, p)
|
||||
if p.startswith("!"):
|
||||
host_list = [ h for h in host_list if h not in that]
|
||||
host_list = [h for h in host_list if h not in that]
|
||||
elif p.startswith("&"):
|
||||
host_list = [ h for h in host_list if h in that ]
|
||||
host_list = [h for h in host_list if h in that]
|
||||
else:
|
||||
host_list.extend(that)
|
||||
|
||||
|
|
|
@ -19,9 +19,9 @@ __metaclass__ = type
|
|||
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, **kwargs):
|
||||
|
||||
return self._flatten(terms)
|
||||
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
'''
|
||||
|
@ -56,20 +54,20 @@ except ImportError:
|
|||
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, **kwargs):
|
||||
if not HAS_KEYRING:
|
||||
raise AnsibleError(u"Can't LOOKUP(keyring): missing required python library 'keyring'")
|
||||
|
||||
display.vvvv(u"keyring: %s" % keyring.get_keyring() )
|
||||
display.vvvv(u"keyring: %s" % keyring.get_keyring())
|
||||
ret = []
|
||||
for term in terms:
|
||||
(servicename, username) = (term.split()[0], term.split()[1])
|
||||
display.vvvv(u"username: %s, servicename: %s " %(username,servicename))
|
||||
password = keyring.get_password(servicename,username)
|
||||
display.vvvv(u"username: %s, servicename: %s " % (username, servicename))
|
||||
password = keyring.get_password(servicename, username)
|
||||
if password is None:
|
||||
raise AnsibleError(u"servicename: %s for user %s not found" % (servicename, username))
|
||||
ret.append(password.rstrip())
|
||||
return ret
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ from ansible.errors import AnsibleError
|
|||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.module_utils._text import to_text
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
|
|
@ -21,6 +21,7 @@ __metaclass__ = type
|
|||
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, **kwargs):
|
||||
|
|
|
@ -134,7 +134,7 @@ class LookupModule(LookupBase):
|
|||
item[1] = ASCENDING
|
||||
elif sort_order == "DESCENDING":
|
||||
item[1] = DESCENDING
|
||||
#else the user knows what s/he is doing and we won't predict. PyMongo will return an error if necessary
|
||||
# else the user knows what s/he is doing and we won't predict. PyMongo will return an error if necessary
|
||||
|
||||
def convert_mongo_result_to_valid_json(self, result):
|
||||
if result is None:
|
||||
|
@ -151,17 +151,16 @@ class LookupModule(LookupBase):
|
|||
elif isinstance(result, dict):
|
||||
new_dict = {}
|
||||
for key in result.keys():
|
||||
value = result[key] # python2 and 3 compatible....
|
||||
value = result[key] # python2 and 3 compatible....
|
||||
new_dict[key] = self.convert_mongo_result_to_valid_json(value)
|
||||
return new_dict
|
||||
elif isinstance(result, datetime.datetime):
|
||||
#epoch
|
||||
return (result - datetime.datetime(1970,1,1)).total_seconds()
|
||||
# epoch
|
||||
return (result - datetime.datetime(1970, 1, 1)). total_seconds()
|
||||
else:
|
||||
#failsafe
|
||||
# failsafe
|
||||
return "{}".format(result)
|
||||
|
||||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
||||
ret = []
|
||||
|
@ -226,7 +225,7 @@ class LookupModule(LookupBase):
|
|||
|
||||
try:
|
||||
client = MongoClient(connection_string, **extra_connection_parameters)
|
||||
results = client[database][collection].find( **term )
|
||||
results = client[database][collection].find(**term)
|
||||
|
||||
for result in results:
|
||||
result = self.convert_mongo_result_to_valid_json(result)
|
||||
|
@ -235,6 +234,4 @@ class LookupModule(LookupBase):
|
|||
except ConnectionFailure as e:
|
||||
raise AnsibleError('unable to connect to database: %s' % str(e))
|
||||
|
||||
|
||||
|
||||
return ret
|
||||
|
|
|
@ -23,6 +23,7 @@ from ansible.errors import AnsibleError, AnsibleUndefinedVariable
|
|||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.utils.listify import listify_lookup_plugin_terms
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def _lookup_variables(self, terms, variables):
|
||||
|
@ -47,10 +48,8 @@ class LookupModule(LookupBase):
|
|||
result = my_list.pop()
|
||||
while len(my_list) > 0:
|
||||
result2 = self._combine(result, my_list.pop())
|
||||
result = result2
|
||||
result = result2
|
||||
new_result = []
|
||||
for x in result:
|
||||
new_result.append(self._flatten(x))
|
||||
return new_result
|
||||
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ def _gen_candidate_chars(characters):
|
|||
# getattr from string expands things like "ascii_letters" and "digits"
|
||||
# into a set of characters.
|
||||
chars.append(to_text(getattr(string, to_native(chars_spec), chars_spec),
|
||||
errors='strict'))
|
||||
errors='strict'))
|
||||
chars = u''.join(chars).replace(u'"', u'').replace(u"'", u'')
|
||||
return chars
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ from distutils import util
|
|||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
||||
# backhacked check_output with input for python 2.7
|
||||
# http://stackoverflow.com/questions/10103551/passing-data-to-subprocess-check-output
|
||||
def check_output2(*popenargs, **kwargs):
|
||||
|
@ -41,7 +42,7 @@ def check_output2(*popenargs, **kwargs):
|
|||
inputdata = None
|
||||
process = subprocess.Popen(*popenargs, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
|
||||
try:
|
||||
out,err = process.communicate(inputdata)
|
||||
out, err = process.communicate(inputdata)
|
||||
except:
|
||||
process.kill()
|
||||
process.wait()
|
||||
|
@ -51,9 +52,10 @@ def check_output2(*popenargs, **kwargs):
|
|||
cmd = kwargs.get("args")
|
||||
if cmd is None:
|
||||
cmd = popenargs[0]
|
||||
raise subprocess.CalledProcessError(retcode, cmd, out+err)
|
||||
raise subprocess.CalledProcessError(retcode, cmd, out + err)
|
||||
return out
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
def parse_params(self, term):
|
||||
# I went with the "traditional" param followed with space separated KV pairs.
|
||||
|
@ -117,7 +119,7 @@ class LookupModule(LookupBase):
|
|||
newpass = self.paramvals['userpass']
|
||||
else:
|
||||
try:
|
||||
newpass = check_output2(['pwgen','-cns',str(self.paramvals['length']), '1']).rstrip()
|
||||
newpass = check_output2(['pwgen', '-cns', str(self.paramvals['length']), '1']).rstrip()
|
||||
except (subprocess.CalledProcessError) as e:
|
||||
raise AnsibleError(e)
|
||||
return newpass
|
||||
|
@ -125,11 +127,11 @@ class LookupModule(LookupBase):
|
|||
def update_password(self):
|
||||
# generate new password, insert old lines from current result and return new password
|
||||
newpass = self.get_newpass()
|
||||
datetime= time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
msg = newpass +'\n' + '\n'.join(self.passoutput[1:])
|
||||
msg+="\nlookup_pass: old password was {} (Updated on {})\n".format(self.password, datetime)
|
||||
datetime = time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
msg = newpass + '\n' + '\n'.join(self.passoutput[1:])
|
||||
msg += "\nlookup_pass: old password was {} (Updated on {})\n".format(self.password, datetime)
|
||||
try:
|
||||
generate = check_output2(['pass','insert','-f','-m',self.passname], input=msg)
|
||||
generate = check_output2(['pass', 'insert', '-f', '-m', self.passname], input=msg)
|
||||
except (subprocess.CalledProcessError) as e:
|
||||
raise AnsibleError(e)
|
||||
return newpass
|
||||
|
@ -141,7 +143,7 @@ class LookupModule(LookupBase):
|
|||
datetime = time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
msg = newpass + '\n' + "lookup_pass: First generated by ansible on {}\n".format(datetime)
|
||||
try:
|
||||
generate = check_output2(['pass','insert','-f','-m',self.passname], input=msg)
|
||||
generate = check_output2(['pass', 'insert', '-f', '-m', self.passname], input=msg)
|
||||
except (subprocess.CalledProcessError) as e:
|
||||
raise AnsibleError(e)
|
||||
return newpass
|
||||
|
@ -160,13 +162,14 @@ class LookupModule(LookupBase):
|
|||
def run(self, terms, variables, **kwargs):
|
||||
result = []
|
||||
self.paramvals = {
|
||||
'subkey':'password',
|
||||
'directory':variables.get('passwordstore'),
|
||||
'create':False,
|
||||
'subkey': 'password',
|
||||
'directory': variables.get('passwordstore'),
|
||||
'create': False,
|
||||
'returnall': False,
|
||||
'overwrite':False,
|
||||
'userpass':'',
|
||||
'length': 16}
|
||||
'overwrite': False,
|
||||
'userpass': '',
|
||||
'length': 16,
|
||||
}
|
||||
|
||||
for term in terms:
|
||||
self.parse_params(term) # parse the input into paramvals
|
||||
|
|
|
@ -22,6 +22,7 @@ import subprocess
|
|||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
|
|
@ -31,9 +31,9 @@ from ansible.plugins.lookup import LookupBase
|
|||
# - two
|
||||
# - three
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, inject=None, **kwargs):
|
||||
|
||||
return [ random.choice(terms) ]
|
||||
|
||||
return [random.choice(terms)]
|
||||
|
|
|
@ -20,22 +20,22 @@ __metaclass__ = type
|
|||
import os
|
||||
import re
|
||||
|
||||
HAVE_REDIS=False
|
||||
HAVE_REDIS = False
|
||||
try:
|
||||
import redis # https://github.com/andymccurdy/redis-py/
|
||||
HAVE_REDIS=True
|
||||
HAVE_REDIS = True
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
||||
# ==============================================================
|
||||
# REDISGET: Obtain value from a GET on a Redis key. Terms
|
||||
# expected: 0 = URL, 1 = Key
|
||||
# URL may be empty, in which case redis://localhost:6379 assumed
|
||||
# --------------------------------------------------------------
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
@ -45,7 +45,7 @@ class LookupModule(LookupBase):
|
|||
|
||||
ret = []
|
||||
for term in terms:
|
||||
(url,key) = term.split(',')
|
||||
(url, key) = term.split(',')
|
||||
if url == "":
|
||||
url = 'redis://localhost:6379'
|
||||
|
||||
|
|
|
@ -146,9 +146,9 @@ class LookupModule(LookupBase):
|
|||
|
||||
def sanity_check(self):
|
||||
if self.count is None and self.end is None:
|
||||
raise AnsibleError( "must specify count or end in with_sequence")
|
||||
raise AnsibleError("must specify count or end in with_sequence")
|
||||
elif self.count is not None and self.end is not None:
|
||||
raise AnsibleError( "can't specify both count and end in with_sequence")
|
||||
raise AnsibleError("can't specify both count and end in with_sequence")
|
||||
elif self.count is not None:
|
||||
# convert count to end
|
||||
if self.count != 0:
|
||||
|
|
|
@ -38,7 +38,7 @@ class LookupModule(LookupBase):
|
|||
def run(self, terms, variables=None, **kwargs):
|
||||
|
||||
if not isinstance(terms, list):
|
||||
terms = [ terms ]
|
||||
terms = [terms]
|
||||
|
||||
ret = []
|
||||
|
||||
|
|
|
@ -33,8 +33,7 @@ class LookupModule(LookupBase):
|
|||
|
||||
def _raise_terms_error(msg=""):
|
||||
raise AnsibleError(
|
||||
"subelements lookup expects a list of two or three items, "
|
||||
+ msg)
|
||||
"subelements lookup expects a list of two or three items, " + msg)
|
||||
|
||||
terms[0] = listify_lookup_plugin_terms(terms[0], templar=self._templar, loader=self._loader)
|
||||
|
||||
|
@ -80,7 +79,7 @@ class LookupModule(LookupBase):
|
|||
for subkey in subelements:
|
||||
if subkey == subelements[-1]:
|
||||
lastsubkey = True
|
||||
if not subkey in subvalue:
|
||||
if subkey not in subvalue:
|
||||
if skip_missing:
|
||||
continue
|
||||
else:
|
||||
|
@ -102,4 +101,3 @@ class LookupModule(LookupBase):
|
|||
ret.append((item0, item1))
|
||||
|
||||
return ret
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ class LookupModule(LookupBase):
|
|||
self._templar.set_available_variables(temp_vars)
|
||||
|
||||
# do the templating
|
||||
res = self._templar.template(template_data, preserve_trailing_newlines=True,convert_data=convert_data_p)
|
||||
res = self._templar.template(template_data, preserve_trailing_newlines=True, convert_data=convert_data_p)
|
||||
ret.append(res)
|
||||
else:
|
||||
raise AnsibleError("the template file %s could not be found for the lookup" % term)
|
||||
|
|
|
@ -47,4 +47,3 @@ class LookupModule(LookupBase):
|
|||
raise AnsibleError("with_together requires at least one element in each list")
|
||||
|
||||
return [self._flatten(x) for x in zip_longest(*my_list, fillvalue=None)]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue