def main(): module = ForemanAnsibleModule( argument_spec=dict( resource=dict(type='str', required=True), search=dict(default=""), full_details=dict(type='bool', aliases=['info'], default='false'), params=dict(type='dict'), organization=dict(), ), ) module_params = module.clean_params() resource = module_params['resource'] search = module_params['search'] params = module_params.get('params', {}) module.connect() if 'organization' in module_params: params['organization_id'] = module.find_resource_by_name('organizations', module_params['organization'], thin=True)['id'] response = module.list_resource(resource, search, params) if module_params['full_details']: resources = [] for found_resource in response: resources.append(module.show_resource(resource, found_resource['id'])) else: resources = response module.exit_json(changed=False, resources=resources)
def main(): module = ForemanAnsibleModule( argument_spec=dict( resource=dict(type='str', required=True), search=dict(default=""), full_details=dict(type='bool', aliases=['info'], default='false'), params=dict(type='dict'), organization=dict(), ), ) module_params = module.clean_params() resource = module_params['resource'] search = module_params['search'] params = module_params.get('params', {}) module.connect() if resource not in module.foremanapi.resources: msg = "Resource '{0}' does not exist in the API. Existing resources: {1}".format(resource, ', '.join(sorted(module.foremanapi.resources))) module.fail_json(msg=msg) if 'organization' in module_params: params['organization_id'] = module.find_resource_by_name('organizations', module_params['organization'], thin=True)['id'] response = module.list_resource(resource, search, params) if module_params['full_details']: resources = [] for found_resource in response: resources.append(module.show_resource(resource, found_resource['id'])) else: resources = response module.exit_json(resources=resources)
def main(): module = ForemanAnsibleModule(argument_spec=dict( name=dict(required=True), value=dict(type='raw'), ), ) entity_dict = module.clean_params() module.connect() entity = module.find_resource_by_name('settings', entity_dict['name'], failsafe=False) if 'value' not in entity_dict: entity_dict['value'] = entity['default'] or '' settings_type = entity['settings_type'] new_value = entity_dict['value'] # Allow to pass integers as string if settings_type == 'integer': new_value = int(new_value) entity_dict['value'] = parameter_value_to_str(new_value, settings_type) old_value = entity['value'] entity['value'] = parameter_value_to_str(old_value, settings_type) changed, entity = module.ensure_entity('settings', entity_dict, entity, state='present', entity_spec=entity_spec) if entity: # Fake the not serialized input value as output entity['value'] = new_value module.exit_json(changed=changed, foreman_setting=entity)