def produce_module_arguments_from_json_schema(json_doc, skip_attrs):
module_arguments = list()
for property in json_doc:
# Skip readonly attributes
if property['readonly'] is True:
continue
# Skip attributes in skip_attrs
if property['name'] in skip_attrs:
continue
key = property['name']
entry = {}
entry['key'] = key
entry['transforms'] = []
# Convert json type to ansible module argument type declaration
entry['type'] = property['type']
# Add choices if applicable
if 'choices' in property:
choice_set = frozenset([choice.lower() for choice in property['choices']])
if choice_set == frozenset(['yes', 'no']):
# Overwrite type to bool
entry['type'] = 'bool'
entry['transforms'] = ['bool_yes_no']
elif choice_set == frozenset(['on', 'off']):
# Overwrite type to bool
entry['type'] = 'bool'
entry['transforms'] = ['bool_on_off']
elif choice_set == frozenset(['enabled', 'disabled']):
entry['choices'] = ['enabled', 'disabled']
else:
entry['choices'] = property['choices']
# Add to ansible modules argument
module_arguments.append(entry)
return module_arguments
评论列表
文章目录