Skip to content

Commit 884d160

Browse files
authored
refactor!: rename role variables to role-prefixed names for ansible-lint compliance (#148)
1 parent d4a293e commit 884d160

15 files changed

Lines changed: 127 additions & 135 deletions

File tree

.config/ansible-lint.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@ exclude_paths:
55
- .yamllint
66
- molecule/
77
- .github/
8+
- galaxy.yml
89

910
# install collection dependencies
1011
offline: false
1112

12-
skip_list:
13-
- yaml[line-length]
14-
1513
warn_list:
16-
- var-naming[no-role-prefix]
1714
- args[module]
18-
- fqcn[action-core]
1915
- meta-runtime[unsupported-version]

roles/icinga_agent/defaults/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ icinga_agent_api_conf: |
2222
accept_config = true
2323
accept_commands = true
2424
25-
icinga2_user:
25+
icinga_agent_icinga2_user:
2626
Debian: nagios
2727
RedHat: icinga
28-
icinga2_group:
28+
icinga_agent_icinga2_group:
2929
Debian: nagios
3030
RedHat: icinga

roles/icinga_agent/tasks/main.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
ansible.builtin.file:
1111
path: /etc/icinga2/repository.d
1212
mode: "0750"
13-
owner: "{{ icinga2_user[ansible_facts.os_family] }}"
14-
group: "{{ icinga2_group[ansible_facts.os_family] }}"
13+
owner: "{{ icinga_agent_icinga2_user[ansible_facts.os_family] }}"
14+
group: "{{ icinga_agent_icinga2_group[ansible_facts.os_family] }}"
1515
state: directory
1616

1717
- name: Create features-* folders in case it is missing
1818
ansible.builtin.file:
1919
path: "{{ item }}"
2020
state: directory
2121
mode: "0750"
22-
owner: "{{ icinga2_user[ansible_facts.os_family] }}"
23-
group: "{{ icinga2_group[ansible_facts.os_family] }}"
22+
owner: "{{ icinga_agent_icinga2_user[ansible_facts.os_family] }}"
23+
group: "{{ icinga_agent_icinga2_group[ansible_facts.os_family] }}"
2424
loop:
2525
- /etc/icinga2/features-available/
2626
- /etc/icinga2/features-enabled/
@@ -29,8 +29,8 @@
2929
ansible.builtin.template:
3030
src: "{{ item }}"
3131
dest: /etc/icinga2/{{ item | basename | regex_replace('.j2', '') }}
32-
owner: "{{ icinga2_user[ansible_facts.os_family] }}"
33-
group: "{{ icinga2_group[ansible_facts.os_family] }}"
32+
owner: "{{ icinga_agent_icinga2_user[ansible_facts.os_family] }}"
33+
group: "{{ icinga_agent_icinga2_group[ansible_facts.os_family] }}"
3434
mode: "0640"
3535
with_fileglob:
3636
- ../templates/configuration/*
@@ -41,8 +41,8 @@
4141
ansible.builtin.template:
4242
src: "{{ item }}"
4343
dest: /etc/icinga2/features-available/{{ item | basename | regex_replace('.j2', '') }}
44-
owner: "{{ icinga2_user[ansible_facts.os_family] }}"
45-
group: "{{ icinga2_group[ansible_facts.os_family] }}"
44+
owner: "{{ icinga_agent_icinga2_user[ansible_facts.os_family] }}"
45+
group: "{{ icinga_agent_icinga2_group[ansible_facts.os_family] }}"
4646
mode: "0640"
4747
with_fileglob:
4848
- ../templates/features/*
@@ -53,8 +53,8 @@
5353
ansible.builtin.template:
5454
src: "{{ item }}"
5555
dest: /etc/icinga2/features-available/{{ item | basename | regex_replace('.j2', '') }}
56-
owner: "{{ icinga2_user[ansible_facts.os_family] }}"
57-
group: "{{ icinga2_group[ansible_facts.os_family] }}"
56+
owner: "{{ icinga_agent_icinga2_user[ansible_facts.os_family] }}"
57+
group: "{{ icinga_agent_icinga2_group[ansible_facts.os_family] }}"
5858
mode: "0640"
5959
with_fileglob:
6060
- "{{ icinga_agent_custom_features_template_path }}"
@@ -86,17 +86,17 @@
8686
path: /var/lib/icinga2/certs/
8787
state: directory
8888
mode: "0750"
89-
owner: "{{ icinga2_user[ansible_facts.os_family] }}"
90-
group: "{{ icinga2_group[ansible_facts.os_family] }}"
89+
owner: "{{ icinga_agent_icinga2_user[ansible_facts.os_family] }}"
90+
group: "{{ icinga_agent_icinga2_group[ansible_facts.os_family] }}"
9191

9292
- name: Generate ticket and save it as a variable
9393
ansible.builtin.command: >
9494
/usr/sbin/icinga2 pki ticket --cn {{ icinga_agent_hostname }} --salt {{ icinga_agent_salt }}
9595
environment:
9696
LD_LIBRARY_PATH: /usr/lib64
97-
register: ticket
97+
register: icinga_agent_ticket
9898
changed_when: false
99-
failed_when: ticket.rc != 0
99+
failed_when: icinga_agent_ticket.rc != 0
100100

101101
- name: Create certificate
102102
ansible.builtin.command: >
@@ -119,7 +119,7 @@
119119
ansible.builtin.command: >
120120
/usr/sbin/icinga2 pki request --host {{ icinga_agent_ca_host }}
121121
--port {{ icinga_agent_ca_host_icinga_port }}
122-
--ticket {{ ticket.stdout }} --key /var/lib/icinga2/certs/{{ icinga_agent_hostname }}.key
122+
--ticket {{ icinga_agent_ticket.stdout }} --key /var/lib/icinga2/certs/{{ icinga_agent_hostname }}.key
123123
--cert /var/lib/icinga2/certs/{{ icinga_agent_hostname }}.crt
124124
--trustedcert /var/lib/icinga2/certs/trusted-master.crt --ca /var/lib/icinga2/certs/ca.crt
125125
args:

roles/icinga_downtime/README.md

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,34 @@ You can add a downtime for a group or a single host, both included or excluded t
55
Or you can set a downtime for a dedicated service of a group or single host.
66
Additionally current downtimes set by Ansible can be removed.
77

8-
98
## Requirements
109

11-
- The name of the ansible hosts inside the inventory has to be exactly the same as the icinga objects, due to using the ansible hostname as icinga target filter.
10+
- The name of the ansible hosts inside the inventory has to be exactly the same as the icinga objects, due to using the ansible hostname as icinga icinga_downtime_target filter.
1211

1312
## Role Variables
1413

1514
| Variable | Required | Default | Description
1615
|-|-|-|-|
17-
| target | mandatory | "" | define icinga-host-objects as target (must be identically in ansibles inventory)
18-
| icinga_action | mandatory | "" | "add_downtimes" or "remove_downtimes"
19-
| icinga_api_uri | mandatory | "" | URL of the Icinga instance could be "https://<hostname>.<domain>
20-
| icinga_api_user | mandatory | "" | User with access to the REST-API
21-
| icinga_api_pwd | mandatory | "" | Password of the User, should be encrypted e.g. with ansible-vault
22-
| icinga_api_port | optional | "5665" | Icinga API port
23-
| duration | optional | "2" | Duration of the downtime
24-
| duration_unit | optional | "hours" | Unit of the duration
25-
| author | optional | "Ansible" | Author of the downtime
26-
| comment | optional | "Downtime set by automation" | Comment to be added to the downtime
27-
| host_downtime | optional | true | Also set a downtime for the host
28-
| service_downtime | optional | true | Also set a downtime for the services
29-
| single_service_downtime | optional | false | Only set a downtime for a single service
30-
| host_service_downtime | optional | false | Only set a downtime for a single host
31-
| service_filter | optional | "" | Add a service filter to the downtime
16+
| icinga_downtime_target | mandatory | "" | define icinga-host-objects as target (must be identically in ansibles inventory)
17+
| icinga_downtime_icinga_action | mandatory | "" | "add_downtimes" or "remove_downtimes"
18+
| icinga_downtime_icinga_api_uri | mandatory | "" | URL of the Icinga instance could be "https://<hostname>.<domain>
19+
| icinga_downtime_icinga_api_user | mandatory | "" | User with access to the REST-API
20+
| icinga_downtime_icinga_api_password | mandatory | "" | Password of the User, should be encrypted e.g. with ansible-vault
21+
| icinga_downtime_icinga_api_port | optional | "5665" | Icinga API port
22+
| icinga_downtime_duration | optional | "2" | Duration of the downtime
23+
| icinga_downtime_duration_unit | optional | "hours" | Unit of the duration
24+
| icinga_downtime_author | optional | "Ansible" | Author of the downtime
25+
| icinga_downtime_comment | optional | "Downtime set by automation" | Comment to be added to the downtime
26+
| icinga_downtime_host_downtime | optional | true | Also set a downtime for the host
27+
| icinga_downtime_service_downtime | optional | true | Also set a downtime for the services
28+
| icinga_downtime_single_service_downtime | optional | false | Only set a downtime for a single service
29+
| icinga_downtime_host_service_downtime | optional | false | Only set a downtime for a single host
30+
| icinga_downtime_service_filter | optional | "" | Add a service filter to the downtime
3231

3332
## Dependencies
3433

3534
- no dependencies
3635

37-
3836
## Examples
3937

4038
```
@@ -50,19 +48,19 @@ Additionally current downtimes set by Ansible can be removed.
5048

5149
```
5250
# command template
53-
ansible-playbook <path_to_playbooks/playbook.yml> -i <path_to_inventory/hosts> -e target="<groupname>" -e icinga_action="<icinga_action>"
51+
ansible-playbook <path_to_playbooks/playbook.yml> -i <path_to_inventory/hosts> -e icinga_downtime_target="<groupname>" -e icinga_downtime_icinga_action="<icinga_downtime_icinga_action>"
5452
5553
# add downtime for all hosts in group devhosts and all of its services
56-
ansible-playbook ./playbooks/playbook.yml -i inventories/inventory/hosts -e target="devhosts" -e icinga_action="add_downtimes"
54+
ansible-playbook ./playbooks/playbook.yml -i inventories/inventory/hosts -e icinga_downtime_target="devhosts" -e icinga_downtime_icinga_action="add_downtimes"
5755
5856
# remove downtime for all hosts in group devhosts and all of its services
59-
ansible-playbook ./playbooks/playbook.yml -i inventories/inventory/hosts -e target="devhosts" -e icinga_action="remove_downtimes"
57+
ansible-playbook ./playbooks/playbook.yml -i inventories/inventory/hosts -e icinga_downtime_target="devhosts" -e icinga_downtime_icinga_action="remove_downtimes"
6058
6159
# add downtime for load-check of all hosts in group devhosts
62-
ansible-playbook ./playbooks/playbook.yml -i inventories/inventory/hosts -e target="devhosts" -e icinga_action="add_downtimes" -e single_service_downtime="true" -e service_filter="load"
60+
ansible-playbook ./playbooks/playbook.yml -i inventories/inventory/hosts -e icinga_downtime_target="devhosts" -e icinga_downtime_icinga_action="add_downtimes" -e single_service_downtime="true" -e service_filter="load"
6361
6462
# add downtime for single host "hostname1" and all its services
65-
ansible-playbook ./playbooks/playbook.yml -i inventories/inventory/hosts -e target="hostname1" -e icinga_action="add_downtimes" -e single_host_downtime="true"
63+
ansible-playbook ./playbooks/playbook.yml -i inventories/inventory/hosts -e icinga_downtime_target="hostname1" -e icinga_downtime_icinga_action="add_downtimes" -e single_host_downtime="true"
6664
```
6765

6866
## Author Information
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
duration: 2
3-
duration_unit: hours
4-
author: Ansible
5-
comment: Downtime set by automation
6-
host_downtime: true
7-
service_downtime: true
8-
single_service_downtime: false
9-
single_host_downtime: false
10-
service_filter: ""
11-
icinga_api_port: "5665"
2+
icinga_downtime_duration: 2
3+
icinga_downtime_duration_unit: hours
4+
icinga_downtime_author: Ansible
5+
icinga_downtime_comment: Downtime set by automation
6+
icinga_downtime_host_downtime: true
7+
icinga_downtime_service_downtime: true
8+
icinga_downtime_single_service_downtime: false
9+
icinga_downtime_single_host_downtime: false
10+
icinga_downtime_service_filter: ""
11+
icinga_downtime_icinga_api_port: "5665"
Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
---
22
- name: Add icinga host downtimes
3+
when: icinga_downtime_host_downtime | bool
34
ansible.builtin.uri:
4-
url: "{{ icinga_api_uri }}:{{ icinga_api_port }}/v1/actions/schedule-downtime?type=Host"
5-
url_username: "{{ icinga_api_user }}"
6-
url_password: "{{ icinga_api_password }}"
5+
url: "{{ icinga_downtime_icinga_api_uri }}:{{ icinga_downtime_icinga_api_port }}/v1/actions/schedule-downtime?type=Host"
6+
url_username: "{{ icinga_downtime_icinga_api_user }}"
7+
url_password: "{{ icinga_downtime_icinga_api_password }}"
78
validate_certs: true
89
method: POST
910
status_code: 200
@@ -13,23 +14,24 @@
1314
body_format: json
1415
body: '{
1516
"filter": "host.name==\"{{ item }}\"",
16-
"author": "{{ author }}",
17-
"comment": "{{ comment }}",
18-
"start_time": "{{ start_time_now }}",
19-
"end_time": "{{ end_time }}",
17+
"author": "{{ icinga_downtime_author }}",
18+
"comment": "{{ icinga_downtime_comment }}",
19+
"start_time": "{{ icinga_downtime_start_time_now }}",
20+
"end_time": "{{ icinga_downtime_end_time }}",
2021
"pretty": true,
2122
"fixed": true,
2223
}'
2324
loop:
24-
- "{{ icinga_host_filter }}"
25-
when:
26-
- host_downtime | bool
25+
- "{{ icinga_downtime_host_filter }}"
2726

2827
- name: Add icinga service downtimes
28+
when:
29+
- icinga_downtime_service_downtime | bool
30+
- icinga_downtime_service_filter == ''
2931
ansible.builtin.uri:
30-
url: "{{ icinga_api_uri }}:{{ icinga_api_port }}/v1/actions/schedule-downtime?type=Service"
31-
url_username: "{{ icinga_api_user }}"
32-
url_password: "{{ icinga_api_password }}"
32+
url: "{{ icinga_downtime_icinga_api_uri }}:{{ icinga_downtime_icinga_api_port }}/v1/actions/schedule-downtime?type=Service"
33+
url_username: "{{ icinga_downtime_icinga_api_user }}"
34+
url_password: "{{ icinga_downtime_icinga_api_password }}"
3335
validate_certs: true
3436
method: POST
3537
status_code: 200
@@ -39,25 +41,25 @@
3941
body_format: json
4042
body: '{
4143
"filter": "host.name==\"{{ item }}\"",
42-
"author": "{{ author }}",
43-
"comment": "{{ comment }}",
44-
"start_time": {{ start_time_now }},
45-
"end_time": {{ end_time }},
44+
"author": "{{ icinga_downtime_author }}",
45+
"comment": "{{ icinga_downtime_comment }}",
46+
"start_time": {{ icinga_downtime_start_time_now }},
47+
"end_time": {{ icinga_downtime_end_time }},
4648
"pretty": true,
4749
"fixed": true,
4850
}'
4951
delegate_to: localhost
5052
loop:
51-
- "{{ icinga_host_filter }}"
52-
when:
53-
- service_downtime | bool
54-
- service_filter == ''
53+
- "{{ icinga_downtime_host_filter }}"
5554

5655
- name: Add icinga single service downtimes
56+
when:
57+
- icinga_downtime_single_service_downtime | bool
58+
- icinga_downtime_service_filter != ''
5759
ansible.builtin.uri:
58-
url: "{{ icinga_api_uri }}:{{ icinga_api_port }}/v1/actions/schedule-downtime?type=Service"
59-
url_username: "{{ icinga_api_user }}"
60-
url_password: "{{ icinga_api_password }}"
60+
url: "{{ icinga_downtime_icinga_api_uri }}:{{ icinga_downtime_icinga_api_port }}/v1/actions/schedule-downtime?type=Service"
61+
url_username: "{{ icinga_downtime_icinga_api_user }}"
62+
url_password: "{{ icinga_downtime_icinga_api_password }}"
6163
validate_certs: true
6264
method: POST
6365
status_code: 200
@@ -66,17 +68,14 @@
6668
Accept: application/json
6769
body_format: json
6870
body: '{
69-
"filter": "host.name==\"{{ item }}\" && match(\"*{{ service_filter }}*\",service.name)",
70-
"author": "{{ author }}",
71-
"comment": "{{ comment }}",
72-
"start_time": {{ start_time_now }},
73-
"end_time": {{ end_time }},
71+
"filter": "host.name==\"{{ item }}\" && match("*{{ icinga_downtime_service_filter }}*",service.name)",
72+
"author": "{{ icinga_downtime_author }}",
73+
"comment": "{{ icinga_downtime_comment }}",
74+
"start_time": {{ icinga_downtime_start_time_now }},
75+
"end_time": {{ icinga_downtime_end_time }},
7476
"pretty": true,
7577
"fixed": true,
7678
}'
7779
delegate_to: localhost
7880
loop:
79-
- "{{ icinga_host_filter }}"
80-
when:
81-
- single_service_downtime | bool
82-
- service_filter != ''
81+
- "{{ icinga_downtime_host_filter }}"
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
11
---
22
- name: Set facts for start_time_now and end_time of the maintenance window
3+
when: icinga_downtime_icinga_action == "add_downtimes"
34
ansible.builtin.set_fact:
4-
start_time_now: "{{ ansible_facts.date_time.epoch }}"
5-
end_time: "{{ ((duration + duration_unit) | community.general.to_time_unit('seconds') | int) + ansible_facts.date_time.epoch | int }}"
5+
icinga_downtime_start_time_now: "{{ ansible_facts.date_time.epoch }}"
6+
icinga_downtime_end_time: >-
7+
{{
8+
((icinga_downtime_duration + icinga_downtime_duration_unit)
9+
| community.general.to_time_unit('seconds') | int)
10+
+ ansible_facts.date_time.epoch | int
11+
}}
612
delegate_to: localhost
713
run_once: true
814
changed_when: false
9-
when:
10-
- icinga_action == "add_downtimes"
1115

1216
- name: Define icinga_host_filter as single host
17+
when: icinga_downtime_single_host_downtime | bool
1318
ansible.builtin.set_fact:
14-
icinga_host_filter: "{{ target }}"
15-
when:
16-
- single_host_downtime | bool
19+
icinga_downtime_host_filter: "{{ icinga_downtime_target }}"
1720

1821
- name: Define icinga_host_filter as group
22+
when: not (icinga_downtime_single_host_downtime | bool)
1923
ansible.builtin.set_fact:
20-
icinga_host_filter: "{{ groups[target] | list | flatten }}"
21-
when:
22-
- not (single_host_downtime | bool)
24+
icinga_downtime_host_filter: "{{ groups[icinga_downtime_target] | list | flatten }}"
2325

2426
- name: Include add_downtimes
27+
when: icinga_downtime_icinga_action == "add_downtimes"
2528
ansible.builtin.include_tasks:
2629
file: add_downtimes.yml
27-
when:
28-
- icinga_action == "add_downtimes"
2930

3031
- name: Include remove_downtimes
32+
when: icinga_downtime_icinga_action == "remove_downtimes"
3133
ansible.builtin.include_tasks:
3234
file: remove_downtimes.yml
33-
when:
34-
- icinga_action == "remove_downtimes"
3535

3636
- name: Include remove_all_downtimes
37+
when: icinga_downtime_icinga_action == "remove_all_downtimes"
3738
ansible.builtin.include_tasks:
3839
file: remove_all_downtimes.yml
39-
when:
40-
- icinga_action == "remove_all_downtimes"
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
- name: Delete all icinga downtimes (host and service)
33
ansible.builtin.uri:
4-
url: "{{ icinga_api_uri }}:{{ icinga_api_port }}/v1/actions/remove-downtime?type=Downtime"
5-
url_username: "{{ icinga_api_user }}"
6-
url_password: "{{ icinga_api_password }}"
4+
url: "{{ icinga_downtime_icinga_api_uri }}:{{ icinga_downtime_icinga_api_port }}/v1/actions/remove-downtime?type=Downtime"
5+
url_username: "{{ icinga_downtime_icinga_api_user }}"
6+
url_password: "{{ icinga_downtime_icinga_api_password }}"
77
validate_certs: true
88
method: POST
99
status_code: 200
@@ -14,4 +14,4 @@
1414
body: '{ "filter": "host.name==\"{{ item }}\"", "pretty": true }'
1515
delegate_to: localhost
1616
with_inventory_hostnames:
17-
- "{{ groups[icinga_host_filter] }}"
17+
- "{{ groups[icinga_downtime_host_filter] }}"

0 commit comments

Comments
 (0)