Add possibility to interpret global parameters value as JSON with rich_params flag (#26180)
This commit is contained in:
parent
f88f4394c8
commit
1fe14da226
2 changed files with 20 additions and 1 deletions
|
@ -145,6 +145,13 @@ want_facts = True
|
|||
# the script for stand-alone Foreman.
|
||||
want_hostcollections = False
|
||||
|
||||
# Whether to interpret global parameters value as JSON (if possible, else
|
||||
# take as is). Only tested with Katello (Red Hat Satellite).
|
||||
# This allows to define lists and dictionaries (and more complicated structures)
|
||||
# variables by entering them as JSON string in Foreman parameters.
|
||||
# Disabled by default as the change would else not be backward compatible.
|
||||
rich_params = False
|
||||
|
||||
[cache]
|
||||
path = .
|
||||
max_age = 60
|
||||
|
|
|
@ -113,6 +113,12 @@ class ForemanInventory(object):
|
|||
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
|
||||
self.want_hostcollections = False
|
||||
|
||||
# Do we want parameters to be interpreted if possible as JSON? (no by default)
|
||||
try:
|
||||
self.rich_params = config.getboolean('ansible', 'rich_params')
|
||||
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
|
||||
self.rich_params = False
|
||||
|
||||
try:
|
||||
self.host_filters = config.get('foreman', 'host_filters')
|
||||
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
|
||||
|
@ -209,7 +215,13 @@ class ForemanInventory(object):
|
|||
|
||||
for param in host_params:
|
||||
name = param['name']
|
||||
params[name] = param['value']
|
||||
if self.rich_params:
|
||||
try:
|
||||
params[name] = json.loads(param['value'])
|
||||
except ValueError:
|
||||
params[name] = param['value']
|
||||
else:
|
||||
params[name] = param['value']
|
||||
|
||||
return params
|
||||
|
||||
|
|
Loading…
Reference in a new issue