Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
def main():
    module = ForemanEntityApypieAnsibleModule(
        argument_spec=dict(
            name=dict(required=True),
            controller=dict(required=True),
            public=dict(defaut='true', type='bool'),
            query=dict(),
            state=dict(default='present',
                       choices=['present_with_defaults', 'present', 'absent']),
        ),
        required_if=(
            ['state', 'present', ['query']],
            ['state', 'present_with_defaults', ['query']],
        ),
        supports_check_mode=True,
    )

    (entity_dict, state) = module.parse_params()

    module.connect()

    search = 'name="{}",controller="{}"'.format(entity_dict['name'],
                                                entity_dict['controller'])
    entity = module.find_resource('bookmarks', search, failsafe=True)

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

    module.exit_json(changed=changed)
Ejemplo n.º 3
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)
Ejemplo n.º 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)
Ejemplo n.º 5
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)