Exemple #1
0
def main():
    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=dict(
            arguments.get_spec('auth', 'namespace'),
            subscription=dict(),
            check=dict(),
        ),
    )

    name = '{0}:{1}'.format(module.params['subscription'] or '*',
                            module.params['check'] or '*')
    client = arguments.get_sensu_client(module.params["auth"])
    path = utils.build_core_v2_path(
        module.params["namespace"],
        "silenced",
        None if name == "*:*" else name,
    )

    try:
        silences = utils.prepare_result_list(utils.get(client, path))
    except errors.Error as e:
        module.fail_json(msg=str(e))

    module.exit_json(changed=False, objects=silences)
Exemple #2
0
def main():
    required_if = [
        ("state", "present", ["address", "token", "version"])
    ]

    module = AnsibleModule(
        supports_check_mode=True,
        required_if=required_if,
        argument_spec=dict(
            arguments.get_spec(
                "auth", "name", "state",
            ),
            address=dict(),
            token=dict(),
            version=dict(
                choices=["v1", "v2"],
            ),
            timeout=dict(
                type="int",
            ),
            max_retries=dict(
                type="int",
            ),
            rate_limit=dict(
                type="float",
            ),
            burst_limit=dict(
                type="int",
            ),
            tls=dict(
                type="dict",
                options=dict(
                    ca_cert=dict(),
                    cname=dict(),
                    client_cert=dict(),
                    client_key=dict(),
                )
            )
        )
    )

    client = arguments.get_sensu_client(module.params['auth'])
    path = utils.build_url_path(
        API_GROUP, API_VERSION, None, 'providers', module.params['name']
    )

    payload = dict(
        type="VaultProvider",
        api_version=API_VERSION,
        metadata=dict(name=module.params["name"]),
        spec=build_vault_provider_spec(module.params)
    )

    try:
        changed, vault_provider = utils.sync_v1(
            module.params['state'], client, path, payload, module.check_mode, do_differ
        )
        module.exit_json(changed=changed, object=vault_provider)
    except errors.Error as e:
        module.fail_json(msg=str(e))
def main():
    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=dict(
            arguments.get_spec("auth"),
            name=dict(),  # Name is not required in info modules.
        ),
    )

    client = arguments.get_sensu_client(module.params["auth"])
    path = utils.build_url_path(
        API_GROUP,
        API_VERSION,
        None,
        "provider",
        module.params["name"],
    )

    try:
        stores = utils.prepare_result_list(utils.get(client, path))
    except errors.Error as e:
        module.fail_json(msg=str(e))

    # We simulate the behavior of v2 API here and only return the spec.
    module.exit_json(
        changed=False,
        objects=[utils.convert_v1_to_v2_response(s) for s in stores])
def main():
    required_if = [("state", "present", ["cluster_role"])]
    module = AnsibleModule(required_if=required_if,
                           supports_check_mode=True,
                           argument_spec=dict(
                               arguments.get_spec("auth", "name", "state"),
                               cluster_role=dict(),
                               users=dict(type="list", ),
                               groups=dict(type="list", ),
                           ))

    msg = role_utils.validate_binding_module_params(module.params)
    if msg:
        module.fail_json(msg=msg)

    client = arguments.get_sensu_client(module.params["auth"])
    path = utils.build_core_v2_path(
        None,
        "clusterrolebindings",
        module.params["name"],
    )
    payload = build_api_payload(module.params)

    try:
        changed, cluster_role_binding = utils.sync(
            module.params["state"], client, path, payload, module.check_mode,
            role_utils.do_role_bindings_differ)
        module.exit_json(changed=changed, object=cluster_role_binding)
    except errors.Error as e:
        module.fail_json(msg=str(e))
Exemple #5
0
def main():
    required_by = {'check': ['entity']}
    module = AnsibleModule(
        supports_check_mode=True,
        required_by=required_by,
        argument_spec=dict(
            arguments.get_spec("auth", "namespace"),
            check=dict(),
            entity=dict(),
        ),
    )

    client = arguments.get_sensu_client(module.params['auth'])
    path = utils.build_core_v2_path(
        module.params['namespace'],
        'events',
        module.params['entity'],
        module.params['check'],
    )

    try:
        events = utils.prepare_result_list(utils.get(client, path))
    except errors.Error as e:
        module.fail_json(msg=str(e))

    module.exit_json(changed=False, objects=events)
Exemple #6
0
def main():
    required_if = [('state', 'present', ['handlers'])]
    module = AnsibleModule(
        supports_check_mode=True,
        required_if=required_if,
        argument_spec=dict(
            arguments.get_spec(
                "auth",
                "name",
                "state",
                "labels",
                "annotations",
            ),
            handlers=dict(type='list'),
        ),
    )

    client = arguments.get_sensu_client(module.params['auth'])
    path = '/handlers/{0}'.format(module.params['name'])
    payload = arguments.get_mutation_payload(module.params, 'handlers')
    payload['type'] = 'set'

    try:
        changed, handler = utils.sync(
            module.params['state'],
            client,
            path,
            payload,
            module.check_mode,
        )
        module.exit_json(changed=changed, object=handler)
    except errors.Error as e:
        module.fail_json(msg=str(e))
Exemple #7
0
def main():
    required_if = [('state', 'enabled', ('password', ))]
    module = AnsibleModule(
        required_if=required_if,
        supports_check_mode=True,
        argument_spec=dict(arguments.get_spec("auth", "name"),
                           state=dict(
                               default='enabled',
                               choices=['enabled', 'disabled'],
                           ),
                           password=dict(no_log=True),
                           groups=dict(type='list', )),
    )

    client = arguments.get_sensu_client(module.params['auth'])
    path = utils.build_core_v2_path(None, 'users', module.params['name'])
    state = module.params['state']

    remote_object = utils.get(client, path)
    if remote_object is None and state == 'disabled' and module.params[
            'password'] is None:
        module.fail_json(msg='Cannot disable a non existent user')

    payload = arguments.get_spec_payload(module.params, 'password', 'groups')
    payload['username'] = module.params['name']
    payload['disabled'] = module.params['state'] == 'disabled'

    try:
        changed, user = sync(remote_object, state, client, path, payload,
                             module.check_mode)
        module.exit_json(changed=changed, object=user)
    except errors.Error as e:
        module.fail_json(msg=str(e))
Exemple #8
0
def main():
    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=dict(
            arguments.get_spec('auth'),
            subscription=dict(),
            check=dict(),
        ),
    )

    name = '{0}:{1}'.format(module.params['subscription'] or '*',
                            module.params['check'] or '*')
    client = arguments.get_sensu_client(module.params["auth"])
    if name != '*:*':
        path = "/silenced/{0}".format(name)
    else:
        path = "/silenced"

    try:
        silences = utils.get(client, path)
    except errors.Error as e:
        module.fail_json(msg=str(e))

    if name != '*:*':
        silences = [silences]
    module.exit_json(changed=False, objects=silences)
def main():
    module = AnsibleModule(supports_check_mode=True,
                           argument_spec=dict(
                               arguments.get_spec(
                                   "auth",
                                   "state",
                               ), ))
    client = arguments.get_sensu_client(module.params['auth'])
    path = utils.build_url_path(API_GROUP, API_VERSION, None, 'providers',
                                'env')
    payload = dict(
        type="Env",
        api_version=API_VERSION,
        metadata=dict(name='env'),
        spec={},
    )

    try:
        changed, env_provider = utils.sync_v1(
            module.params['state'],
            client,
            path,
            payload,
            module.check_mode,
        )
        module.exit_json(changed=changed, object=env_provider)
    except errors.Error as e:
        module.fail_json(msg=str(e))
def main():
    required_if = [
        ('state', 'present', ['action', 'expressions'])
    ]
    module = AnsibleModule(
        required_if=required_if,
        supports_check_mode=True,
        argument_spec=dict(
            arguments.get_spec(
                "auth", "name", "state", "labels", "annotations", "namespace",
            ),
            action=dict(choices=['allow', 'deny']),
            expressions=dict(
                type='list', elements='str',
            ),
            runtime_assets=dict(
                type='list', elements='str',
            ),
        ),
    )

    client = arguments.get_sensu_client(module.params['auth'])
    path = utils.build_core_v2_path(
        module.params['namespace'], 'filters', module.params['name'],
    )
    payload = arguments.get_mutation_payload(
        module.params, 'action', 'expressions', 'runtime_assets'
    )
    try:
        changed, sensu_filter = utils.sync(
            module.params['state'], client, path, payload, module.check_mode,
        )
        module.exit_json(changed=changed, object=sensu_filter)
    except errors.Error as e:
        module.fail_json(msg=str(e))
Exemple #11
0
def main():
    required_if = [('state', 'present', ['command'])]
    module = AnsibleModule(
        supports_check_mode=True,
        required_if=required_if,
        argument_spec=dict(
            arguments.get_spec(
                "auth",
                "name",
                "state",
                "labels",
                "annotations",
                "namespace",
            ),
            command=dict(),
            filters=dict(
                type='list',
                elements='str',
            ),
            mutator=dict(),
            timeout=dict(type='int'),
            env_vars=dict(type='dict'),
            runtime_assets=dict(
                type='list',
                elements='str',
            ),
        ),
    )

    client = arguments.get_sensu_client(module.params['auth'])
    path = utils.build_core_v2_path(
        module.params['namespace'],
        'handlers',
        module.params['name'],
    )
    payload = arguments.get_mutation_payload(module.params, 'command',
                                             'filters', 'mutator', 'timeout',
                                             'runtime_assets')
    payload['type'] = 'pipe'
    if module.params['env_vars']:
        payload['env_vars'] = utils.dict_to_key_value_strings(
            module.params['env_vars'])

    try:
        changed, handler = utils.sync(
            module.params['state'],
            client,
            path,
            payload,
            module.check_mode,
        )
        module.exit_json(changed=changed, object=handler)
    except errors.Error as e:
        module.fail_json(msg=str(e))
Exemple #12
0
def main():
    required_if = [('state', 'present', ['entity_class'])]
    module = AnsibleModule(
        required_if=required_if,
        supports_check_mode=True,
        argument_spec=dict(arguments.get_spec(
            "auth",
            "name",
            "state",
            "labels",
            "annotations",
            "namespace",
        ),
                           entity_class=dict(),
                           subscriptions=dict(
                               type='list',
                               elements='str',
                           ),
                           system=dict(type='dict'),
                           last_seen=dict(type='int'),
                           deregister=dict(type='bool'),
                           deregistration_handler=dict(),
                           redact=dict(
                               type='list',
                               elements='str',
                           ),
                           user=dict()),
    )

    client = arguments.get_sensu_client(module.params['auth'])
    path = utils.build_core_v2_path(
        module.params['namespace'],
        'entities',
        module.params['name'],
    )
    payload = arguments.get_mutation_payload(module.params, 'entity_class',
                                             'subscriptions', 'system',
                                             'last_seen', 'deregister',
                                             'redact', 'user')
    if module.params['deregistration_handler']:
        payload['deregistration'] = dict(
            handler=module.params['deregistration_handler'])
    try:
        changed, entity = utils.sync(
            module.params['state'],
            client,
            path,
            payload,
            module.check_mode,
            do_differ,
        )
        module.exit_json(changed=changed, object=entity)
    except errors.Error as e:
        module.fail_json(msg=str(e))
Exemple #13
0
def main():
    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=dict(arguments.get_spec("auth"), ),
    )
    client = arguments.get_sensu_client(module.params['auth'])
    path = utils.build_core_v2_path(None, 'namespaces')

    try:
        namespaces = utils.get(client, path)
    except errors.Error as e:
        module.fail_json(msg=str(e))

    module.exit_json(changed=False, objects=namespaces)
Exemple #14
0
def main():
    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=dict(
            arguments.get_spec("auth", "name", "state"),
            rules=dict(
                type="list",
                elements="dict",
                options=dict(
                    verbs=dict(
                        required=True,
                        type="list",
                        elements="str",
                        choices=["get", "list", "create", "update", "delete"],
                    ),
                    resources=dict(
                        required=True,
                        type="list",
                        elements="str",
                    ),
                    resource_names=dict(
                        type="list",
                        elements="str",
                    ),
                )
            )
        )
    )

    msg = role_utils.validate_module_params(module.params)
    if msg:
        module.fail_json(msg=msg)

    client = arguments.get_sensu_client(module.params["auth"])
    path = utils.build_core_v2_path(
        None, "clusterroles", module.params["name"],
    )
    payload = arguments.get_mutation_payload(
        module.params, "rules"
    )

    try:
        changed, cluster_role = utils.sync(
            module.params['state'], client, path,
            payload, module.check_mode, role_utils.do_roles_differ
        )
        module.exit_json(changed=changed, object=cluster_role)
    except errors.Error as e:
        module.fail_json(msg=str(e))
Exemple #15
0
def main():
    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=dict(
            arguments.get_spec("auth", "name"),
            state=dict(
                default='enabled',
                choices=['enabled', 'disabled'],
            ),
            password=dict(
                no_log=True
            ),
            groups=dict(
                type='list', elements='str',
            )
        ),
    )

    client = arguments.get_sensu_client(module.params['auth'])
    path = utils.build_core_v2_path(None, 'users', module.params['name'])

    try:
        if not HAS_BCRYPT and client.version >= "5.21.0":
            module.fail_json(
                msg=missing_required_lib('bcrypt'),
                exception=BCRYPT_IMPORT_ERROR,
            )
    except errors.SensuError as e:
        module.fail_json(msg=str(e))

    try:
        remote_object = utils.get(client, path)
    except errors.Error as e:
        module.fail_json(msg=str(e))

    if remote_object is None and module.params['password'] is None:
        module.fail_json(msg='Cannot create new user without a password')

    payload = arguments.get_spec_payload(module.params, 'password', 'groups')
    payload['username'] = module.params['name']
    payload['disabled'] = module.params['state'] == 'disabled'

    try:
        changed, user = sync(
            remote_object, client, path, payload, module.check_mode
        )
        module.exit_json(changed=changed, object=user)
    except errors.Error as e:
        module.fail_json(msg=str(e))
def main():
    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=dict(
            arguments.get_spec("auth"),
            name=dict(),  # Name is not required in info modules.
        ),
    )
    client = arguments.get_sensu_client(module.params["auth"])
    path = utils.build_core_v2_path(None, "users", module.params["name"])

    try:
        users = utils.prepare_result_list(utils.get(client, path))
    except errors.Error as e:
        module.fail_json(msg=str(e))

    module.exit_json(changed=False, objects=users)
Exemple #17
0
def main():
    required_if = [('state', 'present', ['type', 'host', 'port'])]
    module = AnsibleModule(
        supports_check_mode=True,
        required_if=required_if,
        argument_spec=dict(arguments.get_spec(
            "auth",
            "name",
            "state",
            "labels",
            "annotations",
            "namespace",
        ),
                           type=dict(choices=['tcp', 'udp']),
                           filters=dict(
                               type='list',
                               elements='str',
                           ),
                           mutator=dict(),
                           timeout=dict(type='int'),
                           host=dict(),
                           port=dict(type='int')),
    )

    client = arguments.get_sensu_client(module.params['auth'])
    path = utils.build_core_v2_path(
        module.params['namespace'],
        'handlers',
        module.params['name'],
    )
    payload = arguments.get_mutation_payload(module.params, 'type', 'filters',
                                             'mutator', 'timeout')
    payload['socket'] = dict(host=module.params['host'],
                             port=module.params['port'])

    try:
        changed, handler = utils.sync(
            module.params['state'],
            client,
            path,
            payload,
            module.check_mode,
        )
        module.exit_json(changed=changed, object=handler)
    except errors.Error as e:
        module.fail_json(msg=str(e))
Exemple #18
0
def main():
    required_if = [("state", "present", ["builds"])]
    module = AnsibleModule(
        required_if=required_if,
        supports_check_mode=True,
        argument_spec=dict(
            arguments.get_spec(
                "auth",
                "name",
                "namespace",
                "state",
                "labels",
                "annotations",
            ),
            builds=dict(type="list",
                        elements="dict",
                        options=dict(
                            url=dict(required=True, ),
                            sha512=dict(required=True, ),
                            filters=dict(
                                type="list",
                                elements="str",
                            ),
                            headers=dict(type="dict", ),
                        )),
        ),
    )

    msg = validate_module_params(module.params)
    if msg:
        module.fail_json(msg=msg)

    client = arguments.get_sensu_client(module.params["auth"])
    path = utils.build_core_v2_path(
        module.params["namespace"],
        "assets",
        module.params["name"],
    )
    payload = build_api_payload(module.params)

    try:
        changed, asset = utils.sync(module.params["state"], client, path,
                                    payload, module.check_mode, do_differ)
        module.exit_json(changed=changed, object=asset)
    except errors.Error as e:
        module.fail_json(msg=str(e))
Exemple #19
0
def main():
    module = AnsibleModule(supports_check_mode=True,
                           argument_spec=dict(
                               arguments.get_spec('auth'),
                               state=dict(
                                   choices=['enabled', 'disabled'],
                                   required=True,
                               )))
    client = arguments.get_sensu_client(module.params['auth'])
    path = utils.build_core_v2_path(None, 'tessen')
    payload = dict(opt_out=module.params['state'] == 'disabled')

    try:
        changed, tessen = sync(client, path, payload, module.check_mode)
        module.exit_json(changed=changed, object=tessen)
    except errors.Error as e:
        module.fail_json(msg=str(e))
def main():
    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=dict(
            arguments.get_spec("auth", "namespace"),
            timestamp=dict(type='int'),
            entity=dict(required=True),
            check=dict(required=True),
            check_attributes=dict(
                type='dict',
                options=dict(
                    duration=dict(type='float'),
                    executed=dict(type='int'),
                    history=dict(
                        type='list',
                        elements='dict',
                    ),
                    issued=dict(type='int'),
                    last_ok=dict(type='int'),
                    output=dict(),
                    state=dict(choices=['passing', 'failing', 'flapping']),
                    status=dict(
                        choices=['ok', 'warning', 'critical', 'unknown']),
                    total_state_change=dict(type='int'))),
            metric_attributes=dict(type='dict',
                                   options=dict(handlers=dict(type='list',
                                                              elements='str'),
                                                points=dict(
                                                    type='list',
                                                    elements='dict')))))

    client = arguments.get_sensu_client(module.params['auth'])
    path = utils.build_core_v2_path(
        module.params['namespace'],
        'events',
        module.params['entity'],
        module.params['check'],
    )

    try:
        payload = _build_api_payload(client, module.params)
        changed, event = send_event(client, path, payload, module.check_mode)
        module.exit_json(changed=changed, object=event)
    except errors.Error as e:
        module.fail_json(msg=str(e))
def main():
    required_one_of = [['subscription', 'check']]
    module = AnsibleModule(
        supports_check_mode=True,
        required_one_of=required_one_of,
        argument_spec=dict(arguments.get_spec(
            'auth',
            'state',
            'labels',
            'annotations',
            'namespace',
        ),
                           subscription=dict(),
                           check=dict(),
                           begin=dict(type='int', ),
                           expire=dict(type='int', ),
                           expire_on_resolve=dict(type='bool'),
                           reason=dict()),
    )
    name = '{0}:{1}'.format(module.params['subscription'] or '*',
                            module.params['check'] or '*')

    client = arguments.get_sensu_client(module.params['auth'])
    path = utils.build_core_v2_path(
        module.params['namespace'],
        'silenced',
        name,
    )
    # We add name parameter because it is actually required and must match the name that is
    # autogenerated on the API
    module.params['name'] = name
    payload = arguments.get_mutation_payload(module.params, 'subscription',
                                             'check', 'begin', 'expire',
                                             'expire_on_resolve', 'reason')
    try:
        changed, silence = utils.sync(
            module.params['state'],
            client,
            path,
            payload,
            module.check_mode,
        )
        module.exit_json(changed=changed, object=silence)
    except errors.Error as e:
        module.fail_json(msg=str(e))
Exemple #22
0
def main():
    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=arguments.get_spec("auth", "name", "state"),
    )
    module.params['auth']['namespace'] = None
    client = arguments.get_sensu_client(module.params['auth'])
    path = '/namespaces/{0}'.format(module.params['name'])
    payload = arguments.get_spec_payload(
        module.params, 'name'
    )
    try:
        changed, namespace = utils.sync(
            module.params['state'], client, path, payload, module.check_mode,
        )
        module.exit_json(changed=changed, object=namespace)
    except errors.Error as e:
        module.fail_json(msg=str(e))
def main():
    required_if = [('state', 'present', ['command', 'timeout'])]
    module = AnsibleModule(
        required_if=required_if,
        supports_check_mode=True,
        argument_spec=dict(
            arguments.get_spec(
                "auth",
                "name",
                "state",
                "labels",
                "annotations",
                "namespace",
            ),
            command=dict(),
            timeout=dict(type='int', ),
            stdin=dict(type='bool'),
            runtime_assets=dict(
                type='list',
                elements='str',
            ),
        ),
    )

    client = arguments.get_sensu_client(module.params['auth'])
    path = utils.build_core_v2_path(
        module.params['namespace'],
        'hooks',
        module.params['name'],
    )
    payload = arguments.get_mutation_payload(module.params, 'command',
                                             'timeout', 'stdin',
                                             'runtime_assets')
    try:
        changed, hook = utils.sync(
            module.params['state'],
            client,
            path,
            payload,
            module.check_mode,
        )
        module.exit_json(changed=changed, object=hook)
    except errors.Error as e:
        module.fail_json(msg=str(e))
Exemple #24
0
def main():
    module = AnsibleModule(supports_check_mode=True,
                           argument_spec=dict(arguments.get_spec("auth"),
                                              name=dict()))

    client = arguments.get_sensu_client(module.params["auth"])
    path = utils.build_core_v2_path(
        None,
        "clusterrolebindings",
        module.params["name"],
    )

    try:
        cluster_role_bindings = utils.prepare_result_list(
            utils.get(client, path))
    except errors.Error as e:
        module.fail_json(msg=str(e))

    module.exit_json(changed=False, objects=cluster_role_bindings)
Exemple #25
0
def main():
    module = AnsibleModule(supports_check_mode=True,
                           argument_spec=dict(arguments.get_spec("auth"),
                                              name=dict()))

    client = arguments.get_sensu_client(module.params["auth"])
    if module.params["name"]:
        path = "/rolebindings/{0}".format(module.params["name"])
    else:
        path = "/rolebindings"

    try:
        role_bindings = utils.get(client, path)
    except errors.Error as e:
        module.fail_json(msg=str(e))

    if module.params["name"]:
        role_bindings = [role_bindings]
    module.exit_json(changed=False, objects=role_bindings)
def main():
    required_if = [("state", "present", ["dsn"])]
    module = AnsibleModule(
        required_if=required_if,
        supports_check_mode=True,
        argument_spec=dict(arguments.get_spec("auth", "name", "state"),
                           dsn=dict(),
                           pool_size=dict(type="int", )),
    )

    client = arguments.get_sensu_client(module.params["auth"])
    list_path = utils.build_url_path(API_GROUP, API_VERSION, None, "provider")
    resource_path = utils.build_url_path(
        API_GROUP,
        API_VERSION,
        None,
        "provider",
        module.params["name"],
    )
    payload = dict(
        type="PostgresConfig",
        api_version=API_VERSION,
        spec=arguments.get_mutation_payload(module.params, "dsn", "pool_size"),
    )

    try:
        changed, datastore = sync(
            module.params["state"],
            client,
            list_path,
            resource_path,
            payload,
            module.check_mode,
        )
        # We simulate the behavior of v2 API here and only return the spec.
        module.exit_json(
            changed=changed,
            object=datastore and datastore["spec"],
        )
    except errors.Error as e:
        module.fail_json(msg=str(e))
Exemple #27
0
def main():
    required_if = [("state", "present", ["url", "sha512"])]
    module = AnsibleModule(
        required_if=required_if,
        supports_check_mode=True,
        argument_spec=dict(
            arguments.get_spec(
                "auth",
                "name",
                "state",
                "labels",
                "annotations",
            ),
            url=dict(),
            sha512=dict(),
            filters=dict(type="list", ),
            headers=dict(type="dict", ),
        ),
    )

    client = arguments.get_sensu_client(module.params["auth"])
    path = "/assets/{0}".format(module.params["name"])
    payload = arguments.get_mutation_payload(
        module.params,
        "url",
        "sha512",
        "filters",
        "headers",
    )
    try:
        changed, asset = utils.sync(
            module.params["state"],
            client,
            path,
            payload,
            module.check_mode,
        )
        module.exit_json(changed=changed, object=asset)
    except errors.Error as e:
        module.fail_json(msg=str(e))
Exemple #28
0
def main():
    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=dict(arguments.get_spec("auth"), name=dict()),
    )

    module.params['auth'][
        'namespace'] = None  # Making sure we are not fallbacking to default
    client = arguments.get_sensu_client(module.params["auth"])
    if module.params["name"]:
        path = "/clusterroles/{0}".format(module.params["name"])
    else:
        path = "/clusterroles"

    try:
        cluster_roles = utils.get(client, path)
    except errors.Error as e:
        module.fail_json(msg=str(e))

    if module.params["name"]:
        cluster_roles = [cluster_roles]
    module.exit_json(changed=False, objects=cluster_roles)
Exemple #29
0
def main():
    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=dict(
            arguments.get_spec("auth"),
            name=dict(),  # Name is not required in info modules.
        ),
    )

    client = arguments.get_sensu_client(module.params["auth"])
    if module.params["name"]:
        path = "/entities/{0}".format(module.params["name"])
    else:
        path = "/entities"

    try:
        entities = utils.get(client, path)
    except errors.Error as e:
        module.fail_json(msg=str(e))

    if module.params["name"]:
        entities = [entities]
    module.exit_json(changed=False, objects=entities)
Exemple #30
0
def main():
    required_if = [('state', 'present', ['subscriptions', 'command'])]
    mutually_exclusive = [('interval', 'cron')]

    module = AnsibleModule(
        supports_check_mode=True,
        required_if=required_if,
        mutually_exclusive=mutually_exclusive,
        argument_spec=dict(
            arguments.get_spec(
                "auth",
                "name",
                "state",
                "labels",
                "annotations",
                "namespace",
            ),
            command=dict(),
            subscriptions=dict(type='list'),
            handlers=dict(type='list'),
            interval=dict(type='int'),
            cron=dict(),
            publish=dict(type='bool'),
            timeout=dict(type='int'),
            ttl=dict(type='int'),
            stdin=dict(type='bool'),
            env_vars=dict(type='dict'),
            low_flap_threshold=dict(type='int'),
            high_flap_threshold=dict(type='int'),
            runtime_assets=dict(type='list'),
            check_hooks=dict(type='dict'),
            proxy_entity_name=dict(),
            proxy_requests=dict(type='dict',
                                options=dict(
                                    entity_attributes=dict(type='list'),
                                    splay=dict(type='bool'),
                                    splay_coverage=dict(type='int'))),
            output_metric_format=dict(choices=[
                'nagios_perfdata', 'graphite_plaintext', 'influxdb_line',
                'opentsdb_line'
            ]),
            output_metric_handlers=dict(type='list'),
            round_robin=dict(type='bool')))
    validate_module_params(module)
    client = arguments.get_sensu_client(module.params['auth'])
    path = utils.build_core_v2_path(
        module.params['namespace'],
        'checks',
        module.params['name'],
    )
    payload = build_api_payload(module.params)

    try:
        changed, check = utils.sync(
            module.params['state'],
            client,
            path,
            payload,
            module.check_mode,
        )
        module.exit_json(changed=changed, object=check)
    except errors.Error as e:
        module.fail_json(msg=str(e))