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 = 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 = 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 = 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), 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)
def main(): module = ForemanEntityAnsibleModule( argument_spec=dict( name=dict(type='str', required=True), updated_name=dict(type='str'), description=dict(type='str'), provider=dict(type='str', choices=['vmware', 'libvirt', 'ovirt']), provider_params=dict(type='dict'), locations=dict(type='list'), organizations=dict(type='list'), state=dict(type='str', default='present', choices=['present', 'absent', 'present_with_defaults']), # Deprecated provider's specific params, use nested keys in provider_params param instead provider_auth=dict(type='dict'), url=dict(type='str'), display_type=dict(type='str'), datacenter=dict(type='str'), ), required_if=(['state', 'present', ['provider']], ), supports_check_mode=True, ) (entity_dict, state) = module.parse_params() if 'provider' in entity_dict: entity_dict['provider'] = entity_dict['provider'].title() provider_infos = get_provider_infos( provider=entity_dict.get('provider', '')) provider_params = entity_dict.pop('provider_params', dict()) provider_auth = entity_dict.pop('provider_auth', dict()) module.connect() try: # Try to find the compute_resource to work on entity = find_compute_resource(module, name=entity_dict['name'], failsafe=True) except Exception as e: module.fail_json(msg='Failed to find entity: %s ' % e) if 'updated_name' in entity_dict and state == 'present': entity_dict['name'] = entity_dict['updated_name'] if 'organizations' in entity_dict: entity_dict['organizations'] = find_organizations( module, entity_dict['organizations']) if 'locations' in entity_dict: entity_dict['locations'] = find_locations(module, entity_dict['locations']) entity_dict = sanitize_entity_dict(entity_dict, name_map) # Add provider specific params if state in ['present', 'present_with_defaults']: if not provider_infos and not entity: module.fail_json( msg= 'To create a compute resource a valid provider must be supplied' ) for key in provider_infos['params']: # Manage deprecated params if key in provider_auth: entity_dict[key] = provider_auth[key] if key in provider_params: entity_dict[key] = provider_params[key] changed = naildown_entity_state(provider_infos['class'], 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), locations=dict(type='list'), organizations=dict(type='list'), operatingsystems=dict(type='list'), os_family=dict(), path=dict(), state=dict(choices=['present', 'absent'], default='present'), ), supports_check_mode=True, ) if has_import_error: module.fail_json(msg=import_error_msg) medium_dict = dict([(k, v) for (k, v) in module.params.items() if v is not None]) server_url = medium_dict.pop('server_url') username = medium_dict.pop('username') password = medium_dict.pop('password') verify_ssl = medium_dict.pop('verify_ssl') state = medium_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 = 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), 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() name = medium_dict['name'] affects_multiple = name == '*' # sanitize user input, filter unuseful configuration combinations with 'name: *' if affects_multiple: if state == 'present_with_defaults': module.fail_json( msg= "'state: present_with_defaults' and 'name: *' cannot be used together" ) if state == 'absent': if list(medium_dict.keys()) != ['name']: module.fail_json( msg= 'When deleting all installation media, there is no need to specify further parameters %s ' % medium_dict.keys()) try: if affects_multiple: entities = find_entities(Media) else: entities = find_installation_medium(module, name=medium_dict['name'], failsafe=True) except Exception as e: module.fail_json(msg='Failed to find entity: %s ' % e) 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 entities 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 = False if not affects_multiple: changed = naildown_entity_state(Media, medium_dict, entities, state, module) else: medium_dict.pop('name') for entity in entities: 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), network_type=dict(choices=['IPv4', 'IPv6'], default='IPv4'), dns_primary=dict(), dns_secondary=dict(), domains=dict(type='list'), gateway=dict(), network=dict(required=True), cidr=dict(type='int'), mask=dict(), from_ip=dict(), to_ip=dict(), boot_mode=dict(choices=['DHCP', 'Static'], default='DHCP'), ipam=dict(choices=['DHCP', 'Internal DB'], default='DHCP'), dhcp_proxy=dict(), tftp_proxy=dict(), discovery_proxy=dict(), dns_proxy=dict(), remote_execution_proxies=dict(type='list'), vlanid=dict(type='int'), mtu=dict(type='int'), locations=dict(type='list'), organizations=dict(type='list'), ), required_one_of=[['cidr', 'mask']], supports_check_mode=True, ) (entity_dict, state) = module.parse_params() module.connect() try: # Try to find the Subnet to work on entity = find_subnet(module, name=entity_dict['name'], failsafe=True) except Exception as e: module.fail_json(msg='Failed to find entity: %s ' % e) if 'mask' in entity_dict and 'cidr' not in entity_dict: entity_dict['cidr'] = IPNetwork( '%s/%s' % (entity_dict['network'], entity_dict['mask'])).prefixlen elif 'mask' not in entity_dict and 'cidr' in entity_dict: entity_dict['mask'] = IPNetwork( '%s/%s' % (entity_dict['network'], entity_dict['cidr'])).netmask if 'domains' in entity_dict: entity_dict['domains'] = find_domains(module, entity_dict['domains']) for feature in ('dhcp_proxy', 'tftp_proxy', 'discovery_proxy', 'dns_proxy', 'remote_execution_proxies'): if feature in entity_dict: entity_dict[feature] = find_smart_proxy(module, entity_dict[feature]) if 'organizations' in entity_dict: entity_dict['organizations'] = find_organizations( module, entity_dict['organizations']) if 'locations' in entity_dict: entity_dict['locations'] = find_locations(module, entity_dict['locations']) entity_dict = sanitize_entity_dict(entity_dict, name_map) changed = naildown_entity_state(Subnet, 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), network_type=dict(choices=['IPv4', 'IPv6'], default='IPv4'), dns_primary=dict(), dns_secondary=dict(), domains=dict(type='list'), gateway=dict(), network=dict(required=True), cidr=dict(type='int'), mask=dict(), from_ip=dict(), to_ip=dict(), boot_mode=dict(choices=['DHCP', 'Static'], default='DHCP'), ipam=dict(choices=['DHCP', 'Internal DB'], default='DHCP'), dhcp_proxy=dict(), tftp_proxy=dict(), discovery_proxy=dict(), dns_proxy=dict(), remote_execution_proxies=dict(type='list'), vlanid=dict(type='int'), mtu=dict(type='int'), locations=dict(type='list'), organizations=dict(type='list'), state=dict(choices=['present', 'absent'], default='present'), ), required_one_of=[['cidr', 'mask']], 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: # Try to find the Subnet to work on entity = find_subnet(module, name=entity_dict['name'], failsafe=True) except Exception as e: module.fail_json(msg='Failed to find entity: %s ' % e) if 'mask' in entity_dict and 'cidr' not in entity_dict: entity_dict['cidr'] = IPNetwork( '%s/%s' % (entity_dict['network'], entity_dict['mask'])).prefixlen elif 'mask' not in entity_dict and 'cidr' in entity_dict: entity_dict['mask'] = IPNetwork( '%s/%s' % (entity_dict['network'], entity_dict['cidr'])).netmask if 'domains' in entity_dict: entity_dict['domains'] = find_domains(module, entity_dict['domains']) for feature in ('dhcp_proxy', 'tftp_proxy', 'discovery_proxy', 'dns_proxy', 'remote_execution_proxies'): if feature in entity_dict: entity_dict[feature] = find_smart_proxy(module, entity_dict[feature]) if 'organizations' in entity_dict: entity_dict['organizations'] = find_organizations( module, entity_dict['organizations']) if 'locations' in entity_dict: entity_dict['locations'] = find_locations(module, entity_dict['locations']) entity_dict = sanitize_entity_dict(entity_dict, name_map) changed = naildown_entity_state(Subnet, entity_dict, entity, state, module) module.exit_json(changed=changed)