mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix Foreman returning host parameters (#51034)
Foreman (1.20) returns the `all_parameters` key as a list of dicts, not a dict of key-value pairs.
This commit is contained in:
parent
8a5bb7e6c3
commit
919abe17f3
1 changed files with 5 additions and 5 deletions
|
@ -166,8 +166,8 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
|
|||
url = "%s/api/v2/hosts/%s" % (self.foreman_url, hid)
|
||||
ret = self._get_json(url, [404])
|
||||
if not ret or not isinstance(ret, MutableMapping) or not ret.get('all_parameters', False):
|
||||
ret = {'all_parameters': [{}]}
|
||||
return ret.get('all_parameters')[0]
|
||||
ret = []
|
||||
return ret.get('all_parameters')
|
||||
|
||||
def _get_facts_by_id(self, hid):
|
||||
url = "%s/api/v2/hosts/%s/facts" % (self.foreman_url, hid)
|
||||
|
@ -220,11 +220,11 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
|
|||
|
||||
# set host vars from params
|
||||
if self.get_option('want_params'):
|
||||
for k, v in self._get_all_params_by_id(host['id']).items():
|
||||
for p in self._get_all_params_by_id(host['id']):
|
||||
try:
|
||||
self.inventory.set_variable(host['name'], k, v)
|
||||
self.inventory.set_variable(host['name'], p['name'], p['value'])
|
||||
except ValueError as e:
|
||||
self.display.warning("Could not set parameter hostvar for %s, skipping %s: %s" % (host, k, to_native(e)))
|
||||
self.display.warning("Could not set parameter hostvar for %s, skipping %s: %s" % (host, p['name'], to_native(p['value'])))
|
||||
|
||||
# set host vars from facts
|
||||
if self.get_option('want_facts'):
|
||||
|
|
Loading…
Reference in a new issue