mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 12:21:26 -07:00
Config continued (#31024)
* included inventory and callback in new config allow inventory to be configurable updated connection options settings also updated winrm to work with new configs removed now obsolete set_host_overrides added notes for future bcoca, current one is just punting, it's future's problem updated docs per feedback added remove group/host methods to inv data moved fact cache from data to constructed cleaner/better options fix when vars are added extended ignore list to config dicts updated paramiko connection docs removed options from base that paramiko already handles left the look option as it is used by other plugin types resolve delegation updated cache doc options fixed test_script better fragment merge for options fixed proxy command restore ini for proxy normalized options moved pipelining to class updates for host_key_checking restructured mixins * fix typo
This commit is contained in:
parent
46c4f6311a
commit
23b1dbacaf
32 changed files with 667 additions and 366 deletions
|
@ -9,10 +9,21 @@ DOCUMENTATION = '''
|
|||
inventory: script
|
||||
version_added: "2.4"
|
||||
short_description: Executes an inventory script that returns JSON
|
||||
options:
|
||||
cache:
|
||||
description: Toggle the usage of the configured Cache plugin.
|
||||
default: False
|
||||
type: boolean
|
||||
ini:
|
||||
- section: inventory_plugin_script
|
||||
key: cache
|
||||
env:
|
||||
- name: ANSIBLE_INVENTORY_PLUGIN_SCRIPT_CACHE
|
||||
description:
|
||||
- The source provided must an executable that returns Ansible inventory JSON
|
||||
- The source must accept C(--list) and C(--host <hostname>) as arguments.
|
||||
C(--host) will only be used if no C(_meta) key is present (performance optimization)
|
||||
C(--host) will only be used if no C(_meta) key is present.
|
||||
This is a performance optimization as the script would be called per host otherwise.
|
||||
notes:
|
||||
- It takes the place of the previously hardcoded script inventory.
|
||||
- To function it requires being whitelisted in configuration, which is true by default.
|
||||
|
@ -26,10 +37,10 @@ from ansible.errors import AnsibleError, AnsibleParserError
|
|||
from ansible.module_utils.basic import json_dict_bytes_to_unicode
|
||||
from ansible.module_utils.six import iteritems
|
||||
from ansible.module_utils._text import to_native, to_text
|
||||
from ansible.plugins.inventory import BaseInventoryPlugin
|
||||
from ansible.plugins.inventory import BaseInventoryPlugin, Cacheable
|
||||
|
||||
|
||||
class InventoryModule(BaseInventoryPlugin):
|
||||
class InventoryModule(BaseInventoryPlugin, Cacheable):
|
||||
''' Host inventory parser for ansible using external inventory scripts. '''
|
||||
|
||||
NAME = 'script'
|
||||
|
@ -61,17 +72,20 @@ class InventoryModule(BaseInventoryPlugin):
|
|||
|
||||
return valid
|
||||
|
||||
def parse(self, inventory, loader, path, cache=True):
|
||||
def parse(self, inventory, loader, path, cache=None):
|
||||
|
||||
super(InventoryModule, self).parse(inventory, loader, path)
|
||||
|
||||
if cache is None:
|
||||
cache = self._options['cache']
|
||||
|
||||
# Support inventory scripts that are not prefixed with some
|
||||
# path information but happen to be in the current working
|
||||
# directory when '.' is not in PATH.
|
||||
cmd = [path, "--list"]
|
||||
|
||||
try:
|
||||
cache_key = self.get_cache_prefix(path)
|
||||
cache_key = self._get_cache_prefix(path)
|
||||
if not cache or cache_key not in self._cache:
|
||||
try:
|
||||
sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
@ -125,7 +139,7 @@ class InventoryModule(BaseInventoryPlugin):
|
|||
except AttributeError as e:
|
||||
raise AnsibleError("Improperly formatted host information for %s: %s" % (host, to_native(e)))
|
||||
|
||||
self.populate_host_vars([host], got)
|
||||
self._populate_host_vars([host], got)
|
||||
|
||||
except Exception as e:
|
||||
raise AnsibleParserError(to_native(e))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue