mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 20:31:27 -07:00
adding caching to script plugin
This commit is contained in:
parent
b8448fdb90
commit
110fd917d6
1 changed files with 24 additions and 16 deletions
|
@ -82,7 +82,12 @@ class InventoryModule(BaseInventoryPlugin):
|
||||||
# directory when '.' is not in PATH.
|
# directory when '.' is not in PATH.
|
||||||
path = os.path.abspath(path)
|
path = os.path.abspath(path)
|
||||||
cmd = [ path, "--list" ]
|
cmd = [ path, "--list" ]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
cache_key = self.get_cache_prefix(path)
|
||||||
|
if cache and cache_key in inventory.cache:
|
||||||
|
data = inventory.cache[cache_key]
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
|
@ -103,6 +108,9 @@ class InventoryModule(BaseInventoryPlugin):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AnsibleError("Inventory {0} contained characters that cannot be interpreted as UTF-8: {1}".format(path, to_native(e)))
|
raise AnsibleError("Inventory {0} contained characters that cannot be interpreted as UTF-8: {1}".format(path, to_native(e)))
|
||||||
|
|
||||||
|
if cache:
|
||||||
|
inventory.cache[cache_key] = data
|
||||||
|
|
||||||
try:
|
try:
|
||||||
processed = self.loader.load(data)
|
processed = self.loader.load(data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue