1- name: Configuring a handler with missing set parameters should fail
2  sensu_handler:
3    name: "set"
4    type: "set"
5  register: failure
6  ignore_errors: true
7
8- name: Assert that configuring a handler with missing set parameters fails
9  assert:
10    that:
11      - failure is failed
12      - "'the following are missing: handlers' in failure['msg']"
13
14- name: Configure a set handler
15  sensu_handler:
16    name: "set"
17    type: "set"
18    handlers:
19      - anotherhandler
20  register: handler
21
22- name: Retrieve configuration file
23  slurp:
24    src: "{{ handler['file'] }}"
25  register: handler_config
26
27- name: Validate set handler return data
28  assert:
29    that:
30      - "handler is successful"
31      - "handler is changed"
32      - "handler['name'] == 'set'"
33      - "handler['file'] == '/etc/sensu/conf.d/handlers/set.json'"
34      - "handler['config']['type'] == 'set'"
35      - "'anotherhandler' in handler['config']['handlers']"
36      - "handler['config']['handle_flapping'] == false"
37      - "handler['config']['handle_silenced'] == false"
38
39- name: Assert that the handler configuration file is actually configured properly
40  vars:
41    config: "{{ handler_config.content | b64decode | from_json }}"
42  assert:
43    that:
44      - "'set' in config['handlers']"
45      - "config['handlers']['set']['type'] == 'set'"
46      - "'anotherhandler' in config['handlers']['set']['handlers']"
47      - "config['handlers']['set']['handle_flapping'] == false"
48      - "config['handlers']['set']['handle_silenced'] == false"
49