mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 05:40:23 -07:00
Lookups: use Ansible's config manager whenever possible (#5440)
* Start using Ansible's config manager to handle options. * Docs improvements. * Fix documentation, make options actual lookup options. * The cyberarkpassword lookup does too strange things. * The onepassword lookups are converted in #4728, let's not interfere. * Improve docs. * Skip shelvefile as well. * Convert lmdb_kv. * Convert and fix credstash. * Convert manifold. * Drop chef_databag. * Convert dig. * Update examples. * Forgot the most important part. * Fix lmdb_kv docs. * Python 2.6 compatibility. * Convert AnsibleUnicode to str. * Load lookup with lookup loader. * Fix environment handling and error message checking. * Improve docs formatting.
This commit is contained in:
parent
dc66aefa40
commit
e718bd8445
17 changed files with 161 additions and 91 deletions
|
@ -14,23 +14,23 @@ DOCUMENTATION = '''
|
|||
requirements:
|
||||
- hiera (command line utility)
|
||||
description:
|
||||
- Retrieves data from an Puppetmaster node using Hiera as ENC
|
||||
- Retrieves data from an Puppetmaster node using Hiera as ENC.
|
||||
options:
|
||||
_hiera_key:
|
||||
_terms:
|
||||
description:
|
||||
- The list of keys to lookup on the Puppetmaster
|
||||
- The list of keys to lookup on the Puppetmaster.
|
||||
type: list
|
||||
elements: string
|
||||
required: true
|
||||
_bin_file:
|
||||
executable:
|
||||
description:
|
||||
- Binary file to execute Hiera
|
||||
- Binary file to execute Hiera.
|
||||
default: '/usr/bin/hiera'
|
||||
env:
|
||||
- name: ANSIBLE_HIERA_BIN
|
||||
_hierarchy_file:
|
||||
config_file:
|
||||
description:
|
||||
- File that describes the hierarchy of Hiera
|
||||
- File that describes the hierarchy of Hiera.
|
||||
default: '/etc/hiera.yaml'
|
||||
env:
|
||||
- name: ANSIBLE_HIERA_CFG
|
||||
|
@ -67,25 +67,28 @@ from ansible.plugins.lookup import LookupBase
|
|||
from ansible.utils.cmd_functions import run_cmd
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
|
||||
ANSIBLE_HIERA_CFG = os.getenv('ANSIBLE_HIERA_CFG', '/etc/hiera.yaml')
|
||||
ANSIBLE_HIERA_BIN = os.getenv('ANSIBLE_HIERA_BIN', '/usr/bin/hiera')
|
||||
|
||||
|
||||
class Hiera(object):
|
||||
def __init__(self, hiera_cfg, hiera_bin):
|
||||
self.hiera_cfg = hiera_cfg
|
||||
self.hiera_bin = hiera_bin
|
||||
|
||||
def get(self, hiera_key):
|
||||
pargs = [ANSIBLE_HIERA_BIN]
|
||||
pargs.extend(['-c', ANSIBLE_HIERA_CFG])
|
||||
pargs = [self.hiera_bin]
|
||||
pargs.extend(['-c', self.hiera_cfg])
|
||||
|
||||
pargs.extend(hiera_key)
|
||||
|
||||
rc, output, err = run_cmd("{0} -c {1} {2}".format(
|
||||
ANSIBLE_HIERA_BIN, ANSIBLE_HIERA_CFG, hiera_key[0]))
|
||||
self.hiera_bin, self.hiera_cfg, hiera_key[0]))
|
||||
|
||||
return to_text(output.strip())
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
def run(self, terms, variables=''):
|
||||
hiera = Hiera()
|
||||
def run(self, terms, variables=None, **kwargs):
|
||||
self.set_options(var_options=variables, direct=kwargs)
|
||||
|
||||
hiera = Hiera(self.get_option('config_file'), self.get_option('executable'))
|
||||
ret = [hiera.get(terms)]
|
||||
return ret
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue