Change: Code cleanup, create _populate_host method
This commit is contained in:
parent
82b44ad8ad
commit
0c89469c1e
@ -87,9 +87,6 @@ class InventoryModule(BaseInventoryPlugin, Cacheable, Constructable):
|
|||||||
self.groups = self.get_option('groups')
|
self.groups = self.get_option('groups')
|
||||||
self.keyed_groups = self.get_option('keyed_groups')
|
self.keyed_groups = self.get_option('keyed_groups')
|
||||||
|
|
||||||
# self.process_scope = self.get_option('process_scope')
|
|
||||||
# self.process_results = self.get_option('process_results')
|
|
||||||
|
|
||||||
# Prepare Kheops instance
|
# Prepare Kheops instance
|
||||||
self.config_file = self.get_option('config')
|
self.config_file = self.get_option('config')
|
||||||
ansible_config = {
|
ansible_config = {
|
||||||
@ -102,21 +99,32 @@ class InventoryModule(BaseInventoryPlugin, Cacheable, Constructable):
|
|||||||
self.config_file,
|
self.config_file,
|
||||||
path,
|
path,
|
||||||
]
|
]
|
||||||
kheops = AnsibleKheops(configs=configs, display=self.display)
|
self.kheops = AnsibleKheops(configs=configs, display=self.display)
|
||||||
|
|
||||||
# Loop over each hosts
|
# Loop over each hosts
|
||||||
for host_name in inventory.hosts:
|
for host_name in inventory.hosts:
|
||||||
|
try:
|
||||||
|
self._populate_host(host_name)
|
||||||
|
except Exception as err:
|
||||||
|
self.display.error(f"Got errors while processing Kheops lookup for host: %s, %s" % (host_name, err))
|
||||||
|
raise err
|
||||||
|
|
||||||
|
|
||||||
|
def _populate_host(self, host_name):
|
||||||
|
|
||||||
host = self.inventory.get_host(host_name)
|
host = self.inventory.get_host(host_name)
|
||||||
|
|
||||||
ret = kheops.super_lookup(
|
try:
|
||||||
keys=None,
|
ret = self.kheops.super_lookup(
|
||||||
scope=None,
|
keys=None,
|
||||||
_templar=self.templar,
|
scope=None,
|
||||||
_variables=host.get_vars(),
|
_templar=self.templar,
|
||||||
jinja2_native=self.jinja2_native,
|
_variables=host.get_vars(),
|
||||||
#trace=True,
|
jinja2_native=self.jinja2_native,
|
||||||
#explain=True,
|
)
|
||||||
)
|
except AnsibleError as err:
|
||||||
|
self.display.error (f"Could lookup Kheops data for host: {host_name}")
|
||||||
|
raise err
|
||||||
|
|
||||||
# Inject variables into host
|
# Inject variables into host
|
||||||
for key, value in ret.items():
|
for key, value in ret.items():
|
||||||
|
|||||||
@ -243,7 +243,7 @@ class AnsibleKheops:
|
|||||||
raise AnsibleError("Kheops client mode is not implemented")
|
raise AnsibleError("Kheops client mode is not implemented")
|
||||||
|
|
||||||
self.config = config
|
self.config = config
|
||||||
self.display.v("Kheops instance has been created")
|
self.display.v("Kheops instance has been created, with config: %s" % config['instance_config'])
|
||||||
|
|
||||||
def get_config(self):
|
def get_config(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user