Add possibility to interpret global parameters value as JSON with rich_params flag (#26180)

pull/14246/merge
Eric L 7 years ago committed by Chris Alfonso
parent f88f4394c8
commit 1fe14da226

@ -145,6 +145,13 @@ want_facts = True
# the script for stand-alone Foreman. # the script for stand-alone Foreman.
want_hostcollections = False 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] [cache]
path = . path = .
max_age = 60 max_age = 60

@ -113,6 +113,12 @@ class ForemanInventory(object):
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
self.want_hostcollections = False 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: try:
self.host_filters = config.get('foreman', 'host_filters') self.host_filters = config.get('foreman', 'host_filters')
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
@ -209,7 +215,13 @@ class ForemanInventory(object):
for param in host_params: for param in host_params:
name = param['name'] 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 return params

Loading…
Cancel
Save