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)
def main(): argspec = sensu_argument_spec() argspec.update( dict( name=dict(), entity=dict(), ) ) module = AnsibleModule( supports_check_mode=True, argument_spec=argspec, required_by={'name': ['entity']}, ) client = AnsibleSensuClient(module) if module.params['name']: result = [client.get('/events/{0}/{1}'.format(module.params['entity'], module.params['name']))] elif module.params['entity']: result = client.get('/events/{0}'.format(module.params['entity'])) else: result = client.get('/events') module.exit_json(changed=False, events=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('/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 __init__(self, module): self.module = module self.client = AnsibleSensuClient(module) self.params = module.params self.payload = { 'metadata': { 'name': self.params['name'], }, } cluster = module.params['cluster'] if cluster: self.client.namespace = None self.path = '/clusterroles/{0}'.format(self.params['name']) else: self.path = '/roles/{0}'.format(self.params['name']) self.payload['metadata']['namespace'] = module.params['namespace'] for r in self.params['rules']: for key in ('resources', 'verbs', 'resource_names'): if key in r: if not isinstance(r[key], list): r[key] = [r[key]] else: r[key] = None self.payload['rules'] = self.params['rules']
def main(): argspec = sensu_argument_spec() argspec.update(dict(name=dict(), )) module = AnsibleModule( supports_check_mode=True, argument_spec=argspec, ) client = AnsibleSensuClient(module) if module.params['name']: result = [client.get('/hooks/{0}'.format(module.params['name']))] else: result = client.get('/hooks') module.exit_json(changed=False, hooks=result)
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)
def main(): argspec = sensu_argument_spec() argspec.update(dict( name=dict(), subscription=dict(), check=dict(), )) module = AnsibleModule( supports_check_mode=True, argument_spec=argspec, mutually_exclusive=[['name', 'subscription', 'check']], ) client = AnsibleSensuClient(module) if module.params['subscription']: result = client.get('/silenced/subscriptions/{0}'.format( module.params['subscription'])) elif module.params['check']: result = client.get('/silenced/checks/{0}'.format( module.params['check'])) elif module.params['name']: result = [client.get('/silenced/{0}'.format(module.params['name']))] else: result = client.get('/silenced') module.exit_json(changed=False, silenced=result)
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)