summaryrefslogtreecommitdiff
path: root/test/integration/targets/sensu_client/tasks/main.yml
blob: c15685ad81d8f1f577174bff6bd30f1e0d88400a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
- name: Creating a client if the directory doesn't exist should work
  sensu_client:
    subscriptions:
      - default

- name: Set variable for client file
  set_fact:
    client_file: "/etc/sensu/conf.d/client.json"

- name: Insert invalid JSON in the client file
  lineinfile:
    state: "present"
    create: "yes"
    path: "{{ client_file }}"
    line: "{'foo' = bar}"

- name: Configure Sensu client with an existing invalid file
  sensu_client:
    name: "client"
    state: "present"
    subscriptions:
      - default
  register: client

- name: Retrieve configuration file stat
  stat:
    path: "{{ client_file }}"
  register: client_stat

- name: Assert that client data was set successfully and properly
  assert:
    that:
      - "client is successful"
      - "client is changed"
      - "client_stat.stat.exists == true"
      - "client['config']['name'] == 'client'"
      - "'default' in client['config']['subscriptions']"
      - "client['file'] == client_file"

- name: Assert that the client configuration file is actually configured properly
  vars:
    config: "{{ lookup('file', client_file) | from_json }}"
  assert:
    that:
      - "config['client']['keepalives'] == true"
      - "config['client']['name'] == 'client'"
      - "config['client']['safe_mode'] == false"
      - "'default' in config['client']['subscriptions']"

- name: Delete Sensu client configuration
  sensu_client:
    state: "absent"
  register: client_delete

- name: Delete Sensu client configuration (again)
  sensu_client:
    state: "absent"
  register: client_delete_twice

- name: Retrieve configuration file stat
  stat:
    path: "{{ client_file }}"
  register: client_stat

- name: Assert that client deletion was successful
  assert:
    that:
      - "client_delete is successful"
      - "client_delete is changed"
      - "client_delete_twice is successful"
      - "client_delete_twice is not changed"
      - "client_stat.stat.exists == false"

- name: Configuring a client without subscriptions should fail
  sensu_client:
    name: "failure"
  register: failure
  ignore_errors: true

- name: Assert failure to create client
  assert:
    that:
      - failure is failed
      - "'the following are missing: subscriptions' in failure['msg']"

- name: Configure a new client from scratch with custom parameters
  sensu_client:
    name: "custom"
    address: "host.fqdn"
    subscriptions:
      - "default"
      - "webserver"
    redact:
      - "password"
    socket:
      bind: "127.0.0.1"
      port: "3030"
    keepalive:
      thresholds:
        warning: "180"
        critical: "300"
      handlers:
        - "email"
      custom:
        - broadcast: "irc"
      occurrences: "3"
  register: client

- name: Configure a new client from scratch with custom parameters (twice)
  sensu_client:
    name: "custom"
    address: "host.fqdn"
    subscriptions:
      - "default"
      - "webserver"
    redact:
      - "password"
    socket:
      bind: "127.0.0.1"
      port: "3030"
    keepalive:
      thresholds:
        warning: "180"
        critical: "300"
      handlers:
        - "email"
      custom:
        - broadcast: "irc"
      occurrences: "3"
  register: client_twice

- name: Retrieve configuration file stat
  stat:
    path: "{{ client_file }}"
  register: client_stat

- name: Assert that client data was set successfully and properly
  assert:
    that:
      - "client is successful"
      - "client is changed"
      - "client_twice is successful"
      - "client_twice is not changed"
      - "client_stat.stat.exists == true"
      - "client['config']['name'] == 'custom'"
      - "client['config']['address'] == 'host.fqdn'"
      - "'default' in client['config']['subscriptions']"
      - "'webserver' in client['config']['subscriptions']"
      - "'password' in client['config']['redact']"
      - "client['config']['keepalive']['thresholds']['warning'] == '180'"
      - "client['config']['keepalive']['thresholds']['critical'] == '300'"
      - "'email' in client['config']['keepalive']['handlers']"
      - "client['config']['keepalive']['occurrences'] == '3'"
      - "client['file'] == client_file"

- name: Assert that the client configuration file is actually configured properly
  vars:
    config: "{{ lookup('file', client_file) | from_json }}"
  assert:
    that:
      - "config['client']['name'] == 'custom'"
      - "config['client']['address'] == 'host.fqdn'"
      - "config['client']['keepalives'] == true"
      - "config['client']['safe_mode'] == false"
      - "'default' in config['client']['subscriptions']"
      - "'webserver' in config['client']['subscriptions']"
      - "'password' in config['client']['redact']"
      - "config['client']['keepalive']['thresholds']['warning'] == '180'"
      - "config['client']['keepalive']['thresholds']['critical'] == '300'"
      - "'email' in config['client']['keepalive']['handlers']"
      - "config['client']['keepalive']['occurrences'] == '3'"