def main():

    module = ForemanAnsibleModule(
        foreman_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.foreman_params
    resource = module_params['resource']
    search = module_params['search']
    params = module_params.get('params', {})

    with module.api_connection():
        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'], params))
        else:
            resources = response

        module.exit_json(resources=resources)
Exemple #2
0
def main():
    module = ForemanAnsibleModule()

    with module.api_connection():
        status = module.status()

        if 'ping' in module.foremanapi.resources:
            if 'ping' in module.foremanapi.resource('ping').actions:
                ping_action = 'ping'
            else:
                ping_action = 'index'
            ping = module.foremanapi.resource('ping').call(ping_action)
        else:
            ping = None

        module.exit_json(status=status, ping=ping)
Exemple #3
0
def main():
    module = ForemanAnsibleModule(
        foreman_spec={
            'smart_proxy': dict(type='entity', required=True, flat_name='id'),
            'environment': dict(type='entity'),
            'except': dict(type='list', elements='str', choices=['new', 'updated', 'obsolete']),
        },
        supports_check_mode=False,
    )

    with module.api_connection():
        module.auto_lookup_entities()

        if 'except' in module.foreman_params:
            module.foreman_params['except'] = ','.join(module.foreman_params.get('except'))

        result = module.resource_action('smart_proxies', 'import_puppetclasses', record_change=False,
                                        params=_flatten_entity(module.foreman_params, module.foreman_spec))
        if (result.get('environments_updated_puppetclasses', 0) + result.get('environments_with_new_puppetclasses', 0)
                + result.get('environments_obsolete', 0) + result.get('environments_ignored', 0)):
            module.set_changed()

        module.exit_json(result=result)