def main():
    argspec = sensu_argument_spec()
    argspec.update(dict(enabled=dict(
        type='bool',
        default=False,
    ), ))

    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=argspec,
    )

    client = AnsibleSensuClient(module)
    client.namespace = None

    result = client.get('/tessen')

    changed = False
    if result['opt_out'] == module.params['enabled']:
        changed = True
        if not module.check_mode:
            payload = {
                'opt_out': not module.params['enabled'],
            }
            client.put('/tessen', payload)

    module.exit_json(changed=changed)
Ejemplo n.º 2
0
def main():
    argspec = sensu_argument_spec()
    argspec.update(
        dict(
            name=dict(),
            cluster=dict(type='bool', default=False),
        ))

    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=argspec,
    )

    endpoint = '/rolebindings'
    client = AnsibleSensuClient(module)
    if module.params['cluster']:
        client.namespace = None
        endpoint = '/clusterrolebindings'

    if module.params['name']:
        result = [
            client.get('{0}/{1}'.format(endpoint, module.params['name']))
        ]
    else:
        result = client.get(endpoint)

    module.exit_json(changed=False, rolebindings=result)
Ejemplo n.º 3
0
def main():
    argspec = sensu_argument_spec()

    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=argspec,
    )

    client = AnsibleSensuClient(module)
    client.namespace = None

    result = client.get('/cluster/members')

    module.exit_json(changed=False, cluster=result)
def main():
    argspec = sensu_argument_spec()

    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=argspec,
    )

    client = AnsibleSensuClient(module)
    client.namespace = None

    result = client.get('/namespaces')
    result = [x['name'] for x in result]

    module.exit_json(changed=False, namespaces=result)
def main():
    argspec = sensu_argument_spec()
    argspec.update(dict(name=dict(), ))

    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=argspec,
    )

    client = AnsibleSensuClient(module)
    client.namespace = None

    if module.params['name']:
        result = [client.get('/users/{0}'.format(module.params['name']))]
    else:
        result = client.get('/users')

    module.exit_json(changed=False, users=result)
Ejemplo n.º 6
0
def main():
    argspec = sensu_argument_spec()
    argspec.update(
        dict(
            state=dict(
                choices=['present', 'absent'],
                default='present',
            ),
            namespace=dict(
                aliases=['name'],
                required=True,
            ),
        ))

    module = AnsibleModule(
        supports_check_mode=True,
        argument_spec=argspec,
    )

    client = AnsibleSensuClient(module)
    client.namespace = None

    result = client.get('/namespaces')

    for ns in result:
        if ns['name'] == module.params['name']:
            if module.params['state'] == 'present':
                module.exit_json(changed=False)
            if not module.check_mode:
                client.delete('/namespaces/{0}'.format(module.params['name']))
            module.exit_json(changed=True)

    if module.params['state'] == 'absent':
        module.exit_json(changed=False)

    if not module.check_mode:
        payload = {'name': module.params['name']}
        client.put('/namespaces/{0}'.format(module.params['name']), payload)

    module.exit_json(changed=True)