def main(): module = ForemanEntityAnsibleModule( argument_spec=dict( name=dict(required=True), label=dict(), ), supports_check_mode=True, ) (server_params, entity_dict, state) = module.parse_params() try: (server_url, username, password, verify_ssl) = server_params create_server(server_url, (username, password), verify_ssl) except Exception as e: module.fail_json(msg="Failed to connect to Foreman server: %s " % e) ping_server(module) entity = find_organization(module, name=entity_dict['name'], failsafe=True) entity_dict = sanitize_entity_dict(entity_dict, name_map) changed = naildown_entity_state(Organization, entity_dict, entity, state, module) module.exit_json(changed=changed)
def main(module): (server_params, module_params, state) = module.parse_params() name = module_params.get('name') updated_name = module_params.get('updated_name') (server_url, username, password, verify_ssl) = server_params cement.create_server( server_url=server_url, auth=(username, password), verify_ssl=verify_ssl, ) cement.ping_server(module) data = {'name': name} compute_profile = cement.find_compute_profile(module, name=name, failsafe=True) if state == 'present' and updated_name: data['name'] = updated_name data = cement.sanitize_entity_dict(data, name_map) changed = cement.naildown_entity_state(nailgun.entities.ComputeProfile, data, compute_profile, state, module) return changed
def main(module): handle_no_nailgun(module, HAS_NAILGUN_PACKAGE) updated_name = module.params.get('updated_name') state = module.params.get('state') cement.create_server( server_url=module.params.get('server_url'), auth=(module.params.get('username'), module.params.get('password')), verify_ssl=module.params.get('verify_ssl'), ) cement.ping_server(module) data = {'name': module.params.get('name')} compute_profile = cement.find_compute_profile(module, name=data.get('name'), failsafe=True) if state == 'present' and updated_name: data['name'] = updated_name data = sanitize_compute_profile_dict(data) changed = cement.naildown_entity_state(nailgun.entities.ComputeProfile, data, compute_profile, state, module) return changed
def main(module): if has_import_error: module.fail_json(msg=import_error_msg) updated_name = module.params.get('updated_name') state = module.params.get('state') cement.create_server( server_url=module.params.get('server_url'), auth=(module.params.get('username'), module.params.get('password')), verify_ssl=module.params.get('verify_ssl'), ) cement.ping_server(module) data = { 'name': module.params.get('name') } compute_profile = cement.find_compute_profile(module, name=data.get('name'), failsafe=True) if state == 'present' and updated_name: data['name'] = updated_name data = cement.sanitize_entity_dict(data, name_map) changed = cement.naildown_entity_state(nailgun.entities.ComputeProfile, data, compute_profile, state, module) return changed
def main(): module = ForemanEntityAnsibleModule( argument_spec=dict( name=dict(required=True), value=dict(), state=dict(default='present', choices=['present_with_defaults', 'present', 'absent']), ), required_if=( ['state', 'present_with_defaults', ['value']], ['state', 'present', ['value']], ), ) (global_parameter_dict, state) = module.parse_params() module.connect() try: entities = find_entities(CommonParameter, name=global_parameter_dict['name']) if len(entities) > 0: entity = entities[0] else: entity = None except Exception as e: module.fail_json(msg='Failed to find entity: %s ' % e) global_parameter_dict = sanitize_entity_dict(global_parameter_dict, name_map) changed = naildown_entity_state(CommonParameter, global_parameter_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = KatelloEntityAnsibleModule( argument_spec=dict( name=dict(required=True), content_type=dict(required=True, choices=['gpg_key', 'cert']), content=dict(required=True), ), supports_check_mode=True, ) (server_params, entity_dict, state) = module.parse_params() try: (server_url, username, password, verify_ssl) = server_params create_server(server_url, (username, password), verify_ssl) except Exception as e: module.fail_json(msg="Failed to connect to Foreman server: %s " % e) ping_server(module) entity_dict['organization'] = find_organization( module, name=entity_dict['organization']) entity = find_content_credential(module, name=entity_dict['name'], organization=entity_dict['organization'], failsafe=True) entity_dict = sanitize_entity_dict(entity_dict, name_map) changed = naildown_entity_state(ContentCredential, entity_dict, entity, state, module) module.exit_json(changed=changed)
def compute_attribute(module, compute_profile, attributes): # If we don't work on a copy, we hit a TypeError: Value of unknown type: <class 'nailgun.entities.ComputeProfile'> exception # from module.exit_json(changed=changed) method compute_attribute_dict = attributes.copy() for key in ['compute_resource', 'vm_attrs']: if key not in compute_attribute_dict: module.fail_json(msg='compute_attribute must have %s.' % key) try: compute_attribute = find_compute_attribute( module, compute_profile_name=compute_profile.name, compute_resource_name=compute_attribute_dict['compute_resource'], failsafe=True) compute_attribute_dict['compute_resource'] = find_compute_resource( module, name=compute_attribute_dict['compute_resource']) except Exception as e: module.fail_json(msg='Failed to find entity: %s ' % e) if 'compute_profile' not in compute_attribute_dict: compute_attribute_dict['compute_profile'] = compute_profile changed = naildown_entity_state(ComputeAttribute, compute_attribute_dict, compute_attribute, 'present', module) return changed
def main(module): if has_import_error: module.fail_json(msg=import_error_msg) name = module.params.get('name') state = module.params.get('state') provider = module.params.get('provider').title() description = module.params.get('description') locations = module.params.get('locations') organizations = module.params.get('organizations') cement.create_server( server_url=module.params.get('server_url'), auth=(module.params.get('username'), module.params.get('password')), verify_ssl=module.params.get('verify_ssl'), ) cement.ping_server(module) data = {'name': name, 'description': description} compute_resource = cement.find_compute_resource(module, name=data.get('name'), failsafe=True) if organizations: data['organization'] = [ cement.find_organization(module, organization) for organization in organizations ] if locations: data['location'] = [ cement.find_location(module, location) for location in locations ] data['provider'] = provider provider_params = get_provider_params(provider=provider) if state in ['present', 'present_with_defaults']: if not provider_params and not compute_resource: module.fail_json( msg= 'To create a compute resource a valid provider must be supplied' ) for key in provider_params.get('credentials'): data.__setitem__(key, module.params.get('provider_auth').get(key)) for key in provider_params.get('params'): if key not in module.params: module.fail_json(msg='missing required param {}'.format(key)) data.__setitem__(key, module.params.get(key)) changed = cement.naildown_entity_state(provider_params.get('class'), data, compute_resource, state, module) return changed
def main(): module = AnsibleModule( argument_spec=dict( server_url=dict(required=True), username=dict(required=True, no_log=True), password=dict(required=True, no_log=True), verify_ssl=dict(type='bool', default=True), name=dict(required=True), parent=dict(), organizations=dict(type='list'), state=dict(default='present', choices=['present', 'absent']), ), supports_check_mode=True, ) if has_import_error: module.fail_json(msg=import_error_msg) entity_dict = dict([(k, v) for (k, v) in module.params.items() if v is not None]) server_url = entity_dict.pop('server_url') username = entity_dict.pop('username') password = entity_dict.pop('password') verify_ssl = entity_dict.pop('verify_ssl') state = entity_dict.pop('state') try: create_server(server_url, (username, password), verify_ssl) except Exception as e: module.fail_json(msg="Failed to connect to Foreman server: %s " % e) ping_server(module) name_or_title = entity_dict.pop('name') parent = entity_dict.pop('parent', None) # Get short name and parent from provided name parent_from_title, name = split_fqn(name_or_title) entity_dict['name'] = name if parent: entity_dict['parent'] = find_location(module, parent) elif parent_from_title: entity_dict['parent'] = find_location(module, parent_from_title) if 'organizations' in entity_dict: entity_dict['organizations'] = find_organizations( module, entity_dict['organizations']) entity = find_location(module, title=build_fqn(name_or_title, parent), failsafe=True) entity_dict = sanitize_entity_dict(entity_dict, name_map) changed = naildown_entity_state(Location, entity_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = AnsibleModule( argument_spec=dict( server_url=dict(required=True), username=dict(required=True), password=dict(required=True, no_log=True), verify_ssl=dict(type='bool', default=True), name=dict(required=True), description=dict(), dns_proxy=dict(), locations=dict(type='list'), organizations=dict(type='list'), state=dict(choices=['present', 'absent'], default='present'), ), supports_check_mode=True, ) if has_import_error: module.fail_json(msg=import_error_msg) domain_dict = dict([(k, v) for (k, v) in module.params.items() if v is not None]) server_url = domain_dict.pop('server_url') username = domain_dict.pop('username') password = domain_dict.pop('password') verify_ssl = domain_dict.pop('verify_ssl') state = domain_dict.pop('state') try: create_server(server_url, (username, password), verify_ssl) except Exception as e: module.fail_json(msg="Failed to connect to Foreman server: %s " % e) ping_server(module) try: # Try to find the Domain to work on entity = find_domain(module, name=domain_dict['name'], failsafe=True) except Exception as e: module.fail_json(msg='Failed to find entity: %s ' % e) if 'dns_proxy' in domain_dict: domain_dict['dns_proxy'] = find_smart_proxy(module, domain_dict['dns_proxy']) if 'locations' in domain_dict: domain_dict['locations'] = find_locations(module, domain_dict['locations']) if 'organizations' in domain_dict: domain_dict['organizations'] = find_organizations( module, domain_dict['organizations']) domain_dict = sanitize_entity_dict(domain_dict, name_map) changed = naildown_entity_state(Domain, domain_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = ForemanEntityAnsibleModule( argument_spec=dict( operatingsystem=dict(required=True), template_kind=dict(required=True), provisioning_template=dict(required=False), state=dict(default='present', choices=['present', 'present_with_defaults', 'absent']), ), required_if=( ['state', 'present', ['provisioning_template']], ['state', 'present_with_defaults', ['provisioning_template']], ), supports_check_mode=True, ) (server_params, entity_dict, state) = module.parse_params() try: (server_url, username, password, verify_ssl) = server_params create_server(server_url, (username, password), verify_ssl) except Exception as e: module.fail_json(msg="Failed to connect to Foreman server: %s " % e) ping_server(module) entity_dict['operatingsystem'] = find_operating_system_by_title( module, entity_dict['operatingsystem']) entity_dict['template_kind'] = find_entities_by_name( TemplateKind, [entity_dict['template_kind']], module)[0] entity = find_os_default_template( module, operatingsystem=entity_dict['operatingsystem'], template_kind=entity_dict['template_kind'], failsafe=True, ) # Find Provisioning Template if 'provisioning_template' in entity_dict: if state == 'absent': module.fail_json( msg='Provisioning template must not be specified for deletion.' ) entity_dict['provisioning_template'] = find_entities_by_name( ProvisioningTemplate, [entity_dict['provisioning_template']], module)[0] if entity_dict['provisioning_template'].template_kind.id != entity_dict[ 'template_kind'].id: module.fail_json(msg='Provisioning template kind mismatching.') entity_dict = sanitize_os_default_template_dict(entity_dict) changed = naildown_entity_state(OSDefaultTemplate, entity_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = AnsibleModule( argument_spec=dict( server_url=dict(required=True), username=dict(required=True, no_log=True), password=dict(required=True, no_log=True), verify_ssl=dict(type='bool', default=True), product=dict(required=True), organization=dict(required=True), name=dict(required=True), content_type=dict(required=True), url=dict(), download_policy=dict( choices=['background', 'immediate', 'on_demand']), state=dict(default='present', choices=['present_with_defaults', 'present', 'absent']), ), supports_check_mode=True, ) handle_no_nailgun(module, HAS_NAILGUN_PACKAGE) entity_dict = dict([(k, v) for (k, v) in module.params.items() if v is not None]) server_url = entity_dict.pop('server_url') verify_ssl = entity_dict.pop('verify_ssl') username = entity_dict.pop('username') password = entity_dict.pop('password') state = entity_dict.pop('state') try: create_server(server_url, (username, password), verify_ssl) except Exception as e: module.fail_json(msg="Failed to connect to Foreman server: %s " % e) ping_server(module) entity_dict['organization'] = find_organization( module, name=entity_dict['organization']) entity_dict['product'] = find_product( module, name=entity_dict['product'], organization=entity_dict['organization']) entity = find_repository(module, name=entity_dict['name'], product=entity_dict['product'], failsafe=True) entity_dict = sanitize_entity_dict(entity_dict, name_map) changed = naildown_entity_state(Repository, entity_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = KatelloEntityAnsibleModule( argument_spec=dict( product=dict(required=True), label=dict(), name=dict(required=True), content_type=dict( required=True, choices=['docker', 'ostree', 'yum', 'puppet', 'file', 'deb']), url=dict(), gpg_key=dict(), docker_upstream_name=dict(), download_policy=dict( choices=['background', 'immediate', 'on_demand']), mirror_on_sync=dict(type='bool', default=True), state=dict(default='present', choices=['present_with_defaults', 'present', 'absent']), ), supports_check_mode=True, ) (entity_dict, state) = module.parse_params() if entity_dict[ 'content_type'] != 'docker' and 'docker_upstream_name' in entity_dict: module.fail_json( msg= "docker_upstream_name should not be set unless content_type: docker" ) module.connect() entity_dict['organization'] = find_organization( module, name=entity_dict['organization']) entity_dict['product'] = find_product( module, name=entity_dict['product'], organization=entity_dict['organization']) if 'gpg_key' in entity_dict: entity_dict['gpg_key'] = find_content_credential( module, name=entity_dict['gpg_key'], organization=entity_dict['organization']) entity = find_repository(module, name=entity_dict['name'], product=entity_dict['product'], failsafe=True) entity_dict = sanitize_entity_dict(entity_dict, name_map) changed = naildown_entity_state(Repository, entity_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = AnsibleModule( argument_spec=dict( server_url=dict(required=True), username=dict(required=True), password=dict(required=True, no_log=True), verify_ssl=dict(type='bool', default=True), name=dict(required=True), value=dict(), state=dict(required=True, choices=['present_with_defaults', 'present', 'absent']), ), required_if=( ['state', 'present_with_defaults', ['value']], ['state', 'present', ['value']], ), supports_check_mode=True, ) handle_no_nailgun(module, HAS_NAILGUN_PACKAGE) global_parameter_dict = dict([(k, v) for (k, v) in module.params.iteritems() if v is not None]) server_url = global_parameter_dict.pop('server_url') username = global_parameter_dict.pop('username') password = global_parameter_dict.pop('password') verify_ssl = global_parameter_dict.pop('verify_ssl') state = global_parameter_dict.pop('state') try: create_server(server_url, (username, password), verify_ssl) except Exception as e: module.fail_json(msg="Failed to connect to Foreman server: %s " % e) ping_server(module) try: entities = find_entities(CommonParameter, name=global_parameter_dict['name']) if len(entities) > 0: entity = entities[0] else: entity = None except Exception as e: module.fail_json(msg='Failed to find entity: %s ' % e) global_parameter_dict = sanitize_global_parameter_dict( global_parameter_dict) changed = naildown_entity_state(CommonParameter, global_parameter_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = AnsibleModule( argument_spec=dict( server_url=dict(required=True), username=dict(required=True, no_log=True), password=dict(required=True, no_log=True), verify_ssl=dict(type='bool', default=True), name=dict(required=True), organization=dict(required=True), repositories=dict(type='list'), state=dict(default='present', choices=['present_with_defaults', 'present', 'absent']), ), supports_check_mode=True, ) if has_import_error: module.fail_json(msg=import_error_msg) entity_dict = dict([(k, v) for (k, v) in module.params.items() if v is not None]) server_url = entity_dict.pop('server_url') username = entity_dict.pop('username') password = entity_dict.pop('password') verify_ssl = entity_dict.pop('verify_ssl') state = entity_dict.pop('state') try: create_server(server_url, (username, password), verify_ssl) except Exception as e: module.fail_json(msg="Failed to connect to Foreman server: %s " % e) ping_server(module) entity_dict['organization'] = find_organization( module, name=entity_dict['organization']) if 'repositories' in entity_dict: entity_dict['repositories'] = find_repositories( module, entity_dict['repositories'], entity_dict['organization']) content_view_entity = find_content_view( module, name=entity_dict['name'], organization=entity_dict['organization'], failsafe=True) content_view_dict = sanitize_entity_dict(entity_dict, name_map) changed = naildown_entity_state(ContentView, content_view_dict, content_view_entity, state, module) module.exit_json(changed=changed)
def main(): module = AnsibleModule( argument_spec=dict( server_url=dict(required=True), username=dict(required=True, no_log=True), password=dict(required=True, no_log=True), verify_ssl=dict(type='bool', default=True), name=dict(required=True), realm_proxy=dict(type='int', required=True), realm_type=dict(required=True, choices=[ 'Red Hat Identity Management', 'FreeIPA', 'Active Directory' ]), state=dict(default='present', choices=['present', 'absent']), ), supports_check_mode=True, ) if has_import_error: module.fail_json(msg=import_error_msg) realm_dict = dict([(k, v) for (k, v) in module.params.items() if v is not None]) server_url = realm_dict.pop('server_url') username = realm_dict.pop('username') password = realm_dict.pop('password') verify_ssl = realm_dict.pop('verify_ssl') state = realm_dict.pop('state') try: create_server(server_url, (username, password), verify_ssl) except Exception as e: module.fail_json(msg="Failed to connect to Foreman server: %s " % e) ping_server(module) try: entities = find_entities(Realm, name=realm_dict['name']) if len(entities) > 0: entity = entities[0] else: entity = None except Exception as e: module.fail_json(msg='Failed to find entity: %s ' % e) realm_dict = sanitize_realm_dict(realm_dict) changed = naildown_entity_state(Realm, realm_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = AnsibleModule( argument_spec=dict( server_url=dict(required=True), username=dict(required=True, no_log=True), password=dict(required=True, no_log=True), verify_ssl=dict(type='bool', default=True), product=dict(required=True), organization=dict(required=True), name=dict(required=True), content_type=dict(required=True, choices=['docker', 'ostree', 'yum', 'puppet', 'file', 'deb']), url=dict(), docker_upstream_name=dict(), download_policy=dict(choices=['background', 'immediate', 'on_demand']), state=dict(default='present', choices=['present_with_defaults', 'present', 'absent']), ), supports_check_mode=True, ) if has_import_error: module.fail_json(msg=import_error_msg) entity_dict = dict( [(k, v) for (k, v) in module.params.items() if v is not None]) server_url = entity_dict.pop('server_url') verify_ssl = entity_dict.pop('verify_ssl') username = entity_dict.pop('username') password = entity_dict.pop('password') state = entity_dict.pop('state') if entity_dict['content_type'] != 'docker' and 'docker_upstream_name' in entity_dict: module.fail_json(msg="docker_upstream_name should not be set unless content_type: docker") try: create_server(server_url, (username, password), verify_ssl) except Exception as e: module.fail_json(msg="Failed to connect to Foreman server: %s " % e) ping_server(module) entity_dict['organization'] = find_organization(module, name=entity_dict['organization']) entity_dict['product'] = find_product(module, name=entity_dict['product'], organization=entity_dict['organization']) entity = find_repository(module, name=entity_dict['name'], product=entity_dict['product'], failsafe=True) entity_dict = sanitize_entity_dict(entity_dict, name_map) changed = naildown_entity_state(Repository, entity_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = AnsibleModule( argument_spec=dict( server_url=dict(required=True), username=dict(required=True, no_log=True), password=dict(required=True, no_log=True), verify_ssl=dict(type='bool', default=True), name=dict(required=True), parent=dict(), state=dict(default='present', choices=['present', 'absent']), ), supports_check_mode=True, ) if has_import_error: module.fail_json(msg=import_error_msg) entity_dict = dict([(k, v) for (k, v) in module.params.items() if v is not None]) server_url = entity_dict.pop('server_url') username = entity_dict.pop('username') password = entity_dict.pop('password') verify_ssl = entity_dict.pop('verify_ssl') state = entity_dict.pop('state') try: create_server(server_url, (username, password), verify_ssl) except Exception as e: module.fail_json(msg="Failed to connect to Foreman server: %s " % e) ping_server(module) try: entities = find_entities(Location, name=entity_dict['name']) if len(entities) > 0: entity = entities[0] else: entity = None except Exception as e: module.fail_json(msg='Failed to find entity: %s ' % e) parent = entity_dict.pop('parent', None) if parent: entity_dict['parent'] = find_location(module, parent) entity_dict = sanitize_entity_dict(entity_dict, name_map) changed = naildown_entity_state(Location, entity_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = ForemanEntityAnsibleModule( argument_spec=dict( operatingsystem=dict(required=True), template_kind=dict(required=True), provisioning_template=dict(required=False), state=dict(default='present', choices=['present', 'present_with_defaults', 'absent']), ), required_if=( ['state', 'present', ['provisioning_template']], ['state', 'present_with_defaults', ['provisioning_template']], ), ) (entity_dict, state) = module.parse_params() module.connect() entity_dict['operatingsystem'] = find_operating_system_by_title( module, entity_dict['operatingsystem']) entity_dict['template_kind'] = find_entities_by_name( TemplateKind, [entity_dict['template_kind']], module)[0] entity = find_os_default_template( module, operatingsystem=entity_dict['operatingsystem'], template_kind=entity_dict['template_kind'], failsafe=True, ) # Find Provisioning Template if 'provisioning_template' in entity_dict: if state == 'absent': module.fail_json( msg='Provisioning template must not be specified for deletion.' ) entity_dict['provisioning_template'] = find_entities_by_name( ProvisioningTemplate, [entity_dict['provisioning_template']], module)[0] if entity_dict['provisioning_template'].template_kind.id != entity_dict[ 'template_kind'].id: module.fail_json(msg='Provisioning template kind mismatching.') entity_dict = sanitize_os_default_template_dict(entity_dict) changed = naildown_entity_state(OSDefaultTemplate, entity_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = ForemanEntityAnsibleModule( argument_spec=dict( name=dict(required=True), locations=dict(type='list'), organizations=dict(type='list'), operatingsystems=dict(type='list'), os_family=dict(), path=dict(), ), supports_check_mode=True, ) (server_params, medium_dict, state) = module.parse_params() try: (server_url, username, password, verify_ssl) = server_params create_server(server_url, (username, password), verify_ssl) except Exception as e: module.fail_json(msg="Failed to connect to Foreman server: %s " % e) ping_server(module) entity = find_installation_medium(module, name=medium_dict['name'], failsafe=True) if 'operatingsystems' in medium_dict: medium_dict['operatingsystems'] = find_operating_systems_by_title( module, medium_dict['operatingsystems']) if len(medium_dict['operatingsystems'] ) == 1 and 'os_family' not in medium_dict and entity is None: medium_dict['os_family'] = medium_dict['operatingsystems'][ 0].family if 'locations' in medium_dict: medium_dict['locations'] = find_locations(module, medium_dict['locations']) if 'organizations' in medium_dict: medium_dict['organizations'] = find_organizations( module, medium_dict['organizations']) medium_dict = sanitize_entity_dict(medium_dict, name_map) changed = naildown_entity_state(Media, medium_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = AnsibleModule( argument_spec=dict( server_url=dict(required=True), username=dict(required=True), password=dict(required=True, no_log=True), verify_ssl=dict(type='bool', default=True), name=dict(required=True), value=dict(), ), supports_check_mode=True, ) if has_import_error: module.fail_json(msg=import_error_msg) entity_dict = dict([(k, v) for (k, v) in module.params.items() if v is not None]) server_url = entity_dict.pop('server_url') username = entity_dict.pop('username') password = entity_dict.pop('password') verify_ssl = entity_dict.pop('verify_ssl') try: create_server(server_url, (username, password), verify_ssl) except Exception as e: module.fail_json(msg="Failed to connect to Foreman server: %s " % e) ping_server(module) entity = find_setting( module, name=entity_dict['name'], failsafe=False, ) if 'value' not in entity_dict: entity_dict['value'] = entity.default or "" entity_dict = sanitize_entity_dict(entity_dict, name_map) changed = naildown_entity_state(Setting, entity_dict, entity, 'present', module) module.exit_json(changed=changed)
def main(): module = KatelloEntityAnsibleModule( argument_spec=dict( name=dict(required=True), label=dict(), gpg_key=dict(), sync_plan=dict(), description=dict(), state=dict(default='present', choices=['present_with_defaults', 'present', 'absent']), ), supports_check_mode=True, ) (entity_dict, state) = module.parse_params() module.connect() entity_dict['organization'] = find_organization( module, name=entity_dict['organization']) if 'gpg_key' in entity_dict: entity_dict['gpg_key'] = find_content_credential( module, name=entity_dict['gpg_key'], organization=entity_dict['organization']) if 'sync_plan' in entity_dict: entity_dict['sync_plan'] = find_sync_plan( module, name=entity_dict['sync_plan'], organization=entity_dict['organization']) entity = find_product(module, name=entity_dict['name'], organization=entity_dict['organization'], failsafe=True) entity_dict = sanitize_entity_dict(entity_dict, name_map) changed = naildown_entity_state(Product, entity_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = ForemanEntityAnsibleModule( argument_spec=dict( name=dict(required=True), description=dict(), dns_proxy=dict(), locations=dict(type='list'), organizations=dict(type='list'), ), supports_check_mode=True, ) (server_params, domain_dict, state) = module.parse_params() try: (server_url, username, password, verify_ssl) = server_params create_server(server_url, (username, password), verify_ssl) except Exception as e: module.fail_json(msg="Failed to connect to Foreman server: %s " % e) ping_server(module) try: # Try to find the Domain to work on entity = find_domain(module, name=domain_dict['name'], failsafe=True) except Exception as e: module.fail_json(msg='Failed to find entity: %s ' % e) if 'dns_proxy' in domain_dict: domain_dict['dns_proxy'] = find_smart_proxy(module, domain_dict['dns_proxy']) if 'locations' in domain_dict: domain_dict['locations'] = find_locations(module, domain_dict['locations']) if 'organizations' in domain_dict: domain_dict['organizations'] = find_organizations( module, domain_dict['organizations']) domain_dict = sanitize_entity_dict(domain_dict, name_map) changed = naildown_entity_state(Domain, domain_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = ForemanEntityAnsibleModule( argument_spec=dict( name=dict(required=True), locations=dict(type='list'), organizations=dict(type='list'), operatingsystems=dict(type='list'), os_family=dict(), path=dict(), ), supports_check_mode=True, ) (medium_dict, state) = module.parse_params() module.connect() entity = find_installation_medium(module, name=medium_dict['name'], failsafe=True) if 'operatingsystems' in medium_dict: medium_dict['operatingsystems'] = find_operating_systems_by_title( module, medium_dict['operatingsystems']) if len(medium_dict['operatingsystems'] ) == 1 and 'os_family' not in medium_dict and entity is None: medium_dict['os_family'] = medium_dict['operatingsystems'][ 0].family if 'locations' in medium_dict: medium_dict['locations'] = find_locations(module, medium_dict['locations']) if 'organizations' in medium_dict: medium_dict['organizations'] = find_organizations( module, medium_dict['organizations']) medium_dict = sanitize_entity_dict(medium_dict, name_map) changed = naildown_entity_state(Media, medium_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = ForemanEntityAnsibleModule( argument_spec=dict( name=dict(required=True), hostgroup=dict(), location=dict(), organization=dict(), enabled=dict(default='true', type='bool'), state=dict(default='present', choices=['present_with_defaults', 'present', 'absent']), ), required_if=( ['state', 'present_with_defaults', ['hostgroup']], ['state', 'present', ['hostgroup']], ), supports_check_mode=True, ) (host_dict, state) = module.parse_params() module.connect() host_dict['hostgroup'] = find_hostgroup(module, host_dict['hostgroup'], failsafe=True) host_dict['name'] = host_dict['name'] + '.' + \ host_dict['hostgroup'].domain.read().fullname entity = find_host(module, host_dict['name'], failsafe=True) if 'location' in host_dict: host_dict['location'] = find_location(module, host_dict['location']) if 'organization' in host_dict: host_dict['organization'] = find_organization( module, host_dict['organization']) host_dict = sanitize_entity_dict(host_dict, name_map) changed = naildown_entity_state(Host, host_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = ForemanEntityAnsibleModule( argument_spec=dict( name=dict(required=True), value=dict(), state=dict(default='present', choices=['present_with_defaults', 'present', 'absent']), ), required_if=( ['state', 'present_with_defaults', ['value']], ['state', 'present', ['value']], ), supports_check_mode=True, ) (server_params, global_parameter_dict, state) = module.parse_params() try: (server_url, username, password, verify_ssl) = server_params create_server(server_url, (username, password), verify_ssl) except Exception as e: module.fail_json(msg="Failed to connect to Foreman server: %s " % e) ping_server(module) try: entities = find_entities(CommonParameter, name=global_parameter_dict['name']) if len(entities) > 0: entity = entities[0] else: entity = None except Exception as e: module.fail_json(msg='Failed to find entity: %s ' % e) global_parameter_dict = sanitize_entity_dict(global_parameter_dict, name_map) changed = naildown_entity_state(CommonParameter, global_parameter_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = ForemanEntityAnsibleModule( argument_spec=dict( name=dict(required=True), label=dict(), ), supports_check_mode=True, ) (entity_dict, state) = module.parse_params() module.connect() entity = find_organization(module, name=entity_dict['name'], failsafe=True) entity_dict = sanitize_entity_dict(entity_dict, name_map) changed = naildown_entity_state(Organization, entity_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = ForemanEntityAnsibleModule( argument_spec=dict( name=dict(required=True), parent=dict(), organizations=dict(type='list'), ), supports_check_mode=True, ) (server_params, entity_dict, state) = module.parse_params() try: (server_url, username, password, verify_ssl) = server_params create_server(server_url, (username, password), verify_ssl) except Exception as e: module.fail_json(msg="Failed to connect to Foreman server: %s " % e) ping_server(module) name_or_title = entity_dict.pop('name') parent = entity_dict.pop('parent', None) # Get short name and parent from provided name parent_from_title, name = split_fqn(name_or_title) entity_dict['name'] = name if parent: entity_dict['parent'] = find_location(module, parent) elif parent_from_title: entity_dict['parent'] = find_location(module, parent_from_title) if 'organizations' in entity_dict: entity_dict['organizations'] = find_organizations(module, entity_dict['organizations']) entity = find_location(module, title=build_fqn(name_or_title, parent), failsafe=True) entity_dict = sanitize_entity_dict(entity_dict, name_map) changed = naildown_entity_state(Location, entity_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = ForemanEntityAnsibleModule( argument_spec=dict( name=dict(required=True), parent=dict(), organizations=dict(type='list'), ), supports_check_mode=True, ) (entity_dict, state) = module.parse_params() module.connect() name_or_title = entity_dict.pop('name') parent = entity_dict.pop('parent', None) # Get short name and parent from provided name parent_from_title, name = split_fqn(name_or_title) entity_dict['name'] = name if parent: entity_dict['parent'] = find_location(module, parent) elif parent_from_title: entity_dict['parent'] = find_location(module, parent_from_title) if 'organizations' in entity_dict: entity_dict['organizations'] = find_organizations( module, entity_dict['organizations']) entity = find_location(module, title=build_fqn(name_or_title, parent), failsafe=True) entity_dict = sanitize_entity_dict(entity_dict, name_map) changed = naildown_entity_state(Location, entity_dict, entity, state, module) module.exit_json(changed=changed)
def main(): module = ForemanEntityAnsibleModule( argument_spec=dict( name=dict(required=True), locations=dict(type='list'), organizations=dict(type='list'), ), supports_check_mode=True, ) (server_params, entity_dict, state) = module.parse_params() try: (server_url, username, password, verify_ssl) = server_params create_server(server_url, (username, password), verify_ssl) except Exception as e: module.fail_json(msg="Failed to connect to Foreman server: %s " % e) ping_server(module) try: entity = find_environment(module, name=entity_dict['name'], failsafe=True) except Exception as e: module.fail_json(msg='Failed to find entity: %s ' % e) # Set Locations of partition table if 'locations' in entity_dict: entity_dict['locations'] = find_locations(module, entity_dict['locations']) # Set Organizations of partition table if 'organizations' in entity_dict: entity_dict['organizations'] = find_organizations(module, entity_dict['organizations']) entity_dict = sanitize_entity_dict(entity_dict, name_map) changed = naildown_entity_state(Environment, entity_dict, entity, state, module) module.exit_json(changed=changed)