mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-23 20:44:00 -07:00
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
|
|
@ -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…
Add table
Add a link
Reference in a new issue