Example #1
0
def main():
    module = ForemanEntityApypieAnsibleModule(
        argument_spec=dict(
            name=dict(required=True),
            description=dict(),
            dns_proxy=dict(),
            locations=dict(type='list'),
            organizations=dict(type='list'),
        ),
        supports_check_mode=True,
    )

    (domain_dict, state) = module.parse_params()

    module.connect()

    # Try to find the Domain to work on
    entity = module.find_resource_by_name('domains', name=domain_dict['name'], failsafe=True)

    if 'dns_proxy' in domain_dict:
        domain_dict['dns_proxy'] = module.find_resource_by_name('smart_proxies', domain_dict['dns_proxy'], thin=True)

    if 'locations' in domain_dict:
        domain_dict['locations'] = module.find_resources('locations', domain_dict['locations'], thin=True)

    if 'organizations' in domain_dict:
        domain_dict['organizations'] = module.find_resources('organizations', domain_dict['organizations'], thin=True)

    changed = module.ensure_resource_state('domains', domain_dict, entity, state, name_map)

    module.exit_json(changed=changed)
def main():
    module = ForemanEntityApypieAnsibleModule(
        argument_spec=dict(
            name=dict(required=True),
            description=dict(),
            locations=dict(type='list'),
            organizations=dict(type='list'),
        ),
        supports_check_mode=True,
    )

    (entity_dict, state) = module.parse_params()

    module.connect()

    entity = module.find_resource_by_name('roles', name=entity_dict['name'], failsafe=True)

    if 'locations' in entity_dict:
        entity_dict['locations'] = module.find_resources('locations', entity_dict['locations'], thin=True)

    if 'organizations' in entity_dict:
        entity_dict['organizations'] = module.find_resources('organizations', entity_dict['organizations'], thin=True)

    changed = module.ensure_resource_state('roles', entity_dict, entity, state, name_map)

    module.exit_json(changed=changed)
def main():
    module = ForemanEntityApypieAnsibleModule(
        argument_spec=dict(
            name=dict(required=True),
            operatingsystems=dict(type='list'),
        ),
        name_map=name_map,
    )
    entity_dict = module.clean_params()

    module.connect()

    if not module.desired_absent:
        if 'operatingsystems' in entity_dict:
            search_list = [
                "title~{}".format(title)
                for title in entity_dict['operatingsystems']
            ]
            entity_dict['operatingsystems'] = module.find_resources(
                'operatingsystems', search_list, thin=True)

    entity = module.find_resource_by_name('architectures',
                                          name=entity_dict['name'],
                                          failsafe=True)

    changed = module.ensure_resource_state('architectures', entity_dict,
                                           entity)

    module.exit_json(changed=changed)
Example #4
0
def main():
    module = ForemanEntityApypieAnsibleModule(
        argument_spec=dict(
            name=dict(required=True),
            host=dict(required=True),
            port=dict(type='int', default=389),
            account=dict(),
            account_password=dict(no_log=True),
            base_dn=dict(),
            attr_login=dict(),
            attr_firstname=dict(),
            attr_lastname=dict(),
            attr_mail=dict(),
            attr_photo=dict(),
            onthefly_register=dict(type='bool'),
            usergroup_sync=dict(type='bool'),
            tls=dict(type='bool'),
            groups_base=dict(),
            server_type=dict(
                choices=["free_ipa", "active_directory", "posix"]),
            ldap_filter=dict(),
            locations=dict(type='list'),
            organizations=dict(type='list'),
        ),
        supports_check_mode=True,
    )

    (entity_dict, state) = module.parse_params()

    module.connect()

    entity = module.find_resource_by_name('auth_source_ldaps',
                                          name=entity_dict['name'],
                                          failsafe=True)

    if 'locations' in entity_dict:
        entity_dict['locations'] = module.find_resources(
            'locations', entity_dict['locations'], thin=True)

    if 'organizations' in entity_dict:
        entity_dict['organizations'] = module.find_resources(
            'organizations', entity_dict['organizations'], thin=True)

    changed = module.ensure_resource_state('auth_source_ldaps', entity_dict,
                                           entity, state, name_map)

    module.exit_json(changed=changed)
Example #5
0
def main():
    module = ForemanEntityApypieAnsibleModule(
        entity_spec=dict(
            name=dict(required=True),
            network_type=dict(choices=['IPv4', 'IPv6'], default='IPv4'),
            dns_primary=dict(),
            dns_secondary=dict(),
            domains=dict(type='entity_list', flat_name='domain_ids'),
            gateway=dict(),
            network=dict(required=True),
            cidr=dict(type='int'),
            mask=dict(),
            from_ip=dict(flat_name='from'),
            to_ip=dict(flat_name='to'),
            boot_mode=dict(choices=['DHCP', 'Static'], default='DHCP'),
            ipam=dict(choices=['DHCP', 'Internal DB'], default='DHCP'),
            dhcp_proxy=dict(type='entity', flat_name='dhcp_id'),
            tftp_proxy=dict(type='entity', flat_name='tftp_id'),
            discovery_proxy=dict(type='entity', flat_name='discovery_id'),
            dns_proxy=dict(type='entity', flat_name='dns_id'),
            remote_execution_proxies=dict(type='entity_list', flat_name='remote_execution_proxy_ids'),
            vlanid=dict(type='int'),
            mtu=dict(type='int'),
            locations=dict(type='entity_list', flat_name='location_ids'),
            organizations=dict(type='entity_list', flat_name='organization_ids'),
            parameters=dict(type='nested_list', entity_spec=parameter_entity_spec),
        ),
        required_one_of=[['cidr', 'mask']],
    )

    entity_dict = module.clean_params()

    module.connect()

    entity = module.find_resource_by_name('subnets', entity_dict['name'], failsafe=True)

    if not module.desired_absent:
        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'] = str(IPNetwork('%s/%s' % (entity_dict['network'], entity_dict['cidr'])).netmask)

        if 'domains' in entity_dict:
            entity_dict['domains'] = module.find_resources('domains', entity_dict['domains'], thin=True)

        for feature in ('dhcp_proxy', 'tftp_proxy', 'discovery_proxy', 'dns_proxy'):
            if feature in entity_dict:
                entity_dict[feature] = module.find_resource_by_name('smart_proxies', entity_dict[feature], thin=True)

        if 'remote_execution_proxies' in entity_dict:
            entity_dict['remote_execution_proxies'] = module.find_resources_by_name('smart_proxies', entity_dict['remote_execution_proxies'], thin=True)

        if 'organizations' in entity_dict:
            entity_dict['organizations'] = module.find_resources_by_name('organizations', entity_dict['organizations'], thin=True)

        if 'locations' in entity_dict:
            entity_dict['locations'] = module.find_resources_by_title('locations', entity_dict['locations'], thin=True)

    parameters = entity_dict.get('parameters')

    changed, subnet = module.ensure_entity('subnets', entity_dict, entity)

    if subnet:
        scope = {'subnet_id': subnet['id']}
        changed |= module.ensure_scoped_parameters(scope, entity, parameters)

    module.exit_json(changed=changed)
Example #6
0
def main():
    module = ForemanEntityApypieAnsibleModule(argument_spec=dict(
        name=dict(required=True),
        locations=dict(type='list'),
        organizations=dict(type='list'),
        operatingsystems=dict(type='list'),
        os_family=dict(),
        path=dict(),
    ), )

    entity_dict = module.clean_params()

    module.connect()
    name = entity_dict['name']

    affects_multiple = name == '*'
    # sanitize user input, filter unuseful configuration combinations with 'name: *'
    if affects_multiple:
        if module.state == 'present_with_defaults':
            module.fail_json(
                msg=
                "'state: present_with_defaults' and 'name: *' cannot be used together"
            )
        if module.desired_absent:
            if list(entity_dict.keys()) != ['name']:
                module.fail_json(
                    msg=
                    'When deleting all installation media, there is no need to specify further parameters %s '
                    % entity_dict.keys())

    if affects_multiple:
        entities = module.list_resource('media')
        if not module.desired_absent:  # not 'thin'
            entities = [
                module.show_resource('media', entity['id'])
                for entity in entities
            ]
        if not entities:
            # Nothing to do shortcut to exit
            module.exit_json(changed=False)
    else:
        entity = module.find_resource_by_name('media',
                                              name=entity_dict['name'],
                                              failsafe=True)

    if not module.desired_absent:
        if 'operatingsystems' in entity_dict:
            search_list = [
                'title~"{}"'.format(title)
                for title in entity_dict['operatingsystems']
            ]
            entity_dict['operatingsystems'] = module.find_resources(
                'operatingsystems', search_list=search_list, thin=True)
            if not affects_multiple and len(
                    entity_dict['operatingsystems']
            ) == 1 and 'os_family' not in entity_dict and entity is None:
                entity_dict['os_family'] = module.show_resource(
                    'operatingsystems',
                    entity_dict['operatingsystems'][0]['id'])['family']

        if 'locations' in entity_dict:
            entity_dict['locations'] = module.find_resources_by_title(
                'locations', entity_dict['locations'], thin=True)

        if 'organizations' in entity_dict:
            entity_dict['organizations'] = module.find_resources_by_name(
                'organizations', entity_dict['organizations'], thin=True)

    changed = False
    if not affects_multiple:
        changed = module.ensure_resource_state('media',
                                               entity_dict,
                                               entity,
                                               name_map=name_map)
    else:
        entity_dict.pop('name')
        for entity in entities:
            changed |= module.ensure_resource_state('media',
                                                    entity_dict,
                                                    entity,
                                                    name_map=name_map)

    module.exit_json(changed=changed)
Example #7
0
def main():
    module = ForemanEntityApypieAnsibleModule(
        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']],
    )

    entity_dict = module.clean_params()

    module.connect()

    entity = module.find_resource_by_name('subnets',
                                          entity_dict['name'],
                                          failsafe=True)

    if not module.desired_absent:
        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'] = str(
                IPNetwork(
                    '%s/%s' %
                    (entity_dict['network'], entity_dict['cidr'])).netmask)

        if 'domains' in entity_dict:
            entity_dict['domains'] = module.find_resources(
                'domains', entity_dict['domains'], thin=True)

        # TODO should remote_execution seach for a list?
        for feature in ('dhcp_proxy', 'tftp_proxy', 'discovery_proxy',
                        'dns_proxy', 'remote_execution_proxies'):
            if feature in entity_dict:
                entity_dict[feature] = module.find_resource_by_name(
                    'smart_proxies', entity_dict[feature], thin=True)

        if 'organizations' in entity_dict:
            entity_dict['organizations'] = module.find_resources_by_name(
                'organizations', entity_dict['organizations'], thin=True)

        if 'locations' in entity_dict:
            entity_dict['locations'] = module.find_resources_by_title(
                'locations', entity_dict['locations'], thin=True)

    changed = module.ensure_resource_state('subnets',
                                           entity_dict,
                                           entity,
                                           name_map=name_map)

    module.exit_json(changed=changed)
Example #8
0
def main():
    module = ForemanEntityApypieAnsibleModule(
        argument_spec=dict(name=dict(required=True),
                           firstname=dict(required=False),
                           lastname=dict(required=False),
                           mail=dict(required=False),
                           description=dict(required=False),
                           admin=dict(required=False,
                                      type='bool',
                                      default=False),
                           user_password=dict(required=False, no_log=True),
                           default_location=dict(required=False),
                           default_organization=dict(required=False),
                           auth_source=dict(required=False),
                           timezone=dict(required=False,
                                         choices=timezone_list),
                           locale=dict(required=False, choices=locale_list),
                           roles=dict(required=False, type='list'),
                           locations=dict(required=False, type='list'),
                           organizations=dict(required=False, type='list')),
        supports_check_mode=True,
    )

    (entity_dict, state) = module.parse_params()

    module.connect()

    search = 'login="******"'.format(entity_dict['name'])
    entity = module.find_resource('users', search, failsafe=True)

    if 'mail' not in entity_dict:
        entity_dict['mail'] = entity['mail']

    if 'default_location' in entity_dict:
        entity_dict['default_location'] = module.find_resource_by_name(
            'locations', entity_dict['default_location'], thin=True)['id']

    if 'default_organization' in entity_dict:
        entity_dict['default_organization'] = module.find_resource_by_name(
            'organizations', entity_dict['default_organization'],
            thin=True)['id']

    if 'auth_source' in entity_dict:
        entity_dict['auth_source'] = module.find_resource_by_name(
            'auth_sources', entity_dict['auth_source'], thin=True)['id']

    if 'roles' in entity_dict:
        entity_dict['roles'] = module.find_resources('roles',
                                                     entity_dict['roles'],
                                                     thin=True)

    if 'locations' in entity_dict:
        entity_dict['locations'] = module.find_resources(
            'locations', entity_dict['locations'], thin=True)

    if 'organizations' in entity_dict:
        entity_dict['organizations'] = module.find_resources(
            'organizations', entity_dict['organizations'], thin=True)

    check_missing = None
    if 'user_password' in entity_dict:
        check_missing = [name_map['user_password']]

    changed = module.ensure_resource_state('users',
                                           entity_dict,
                                           entity,
                                           state,
                                           name_map,
                                           check_missing=check_missing)

    module.exit_json(changed=changed, entity_dict=entity_dict)