Skip to content

Commit 5ce7c5e

Browse files
beechesIIxFuture603z-bsod
authored
Add molecule for role icinga_plugins (#18)
* added Molecule tests for centos7, rocky linux 8 and rocky linux 8 Co-authored-by: xFuture603 <daniel.xfuture@googlemail.com> Co-authored-by: Christoph <z-bsod@users.noreply.github.com>
1 parent ae1d36d commit 5ce7c5e

8 files changed

Lines changed: 199 additions & 15 deletions

File tree

.github/workflows/CI.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,18 @@ jobs:
8989
python3 -m pip install -r requirements.txt
9090
working-directory: ansible_collections/t_systems_mms/ansible_collection_icinga
9191

92-
- name: Test with molecule
92+
- name: Test role icinga_agent with molecule
9393
run: molecule test
9494
working-directory: ansible_collections/t_systems_mms/ansible_collection_icinga/roles/icinga_agent
9595
env:
9696
PY_COLORS: '1'
9797
ANSIBLE_FORCE_COLOR: '1'
9898
MOLECULE_DISTRO: ${{ matrix.distro }}
99+
100+
- name: Test role icinga_plugins with molecule
101+
run: molecule test
102+
working-directory: ansible_collections/t_systems_mms/ansible_collection_icinga/roles/icinga_plugins
103+
env:
104+
PY_COLORS: '1'
105+
ANSIBLE_FORCE_COLOR: '1'
106+
MOLECULE_DISTRO: ${{ matrix.distro }}

roles/icinga_agent/molecule/default/converge.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,6 @@
188188
- "result_api_conf.group == 'nagios'"
189189
when: ansible_os_family == 'Debian'
190190

191-
# - name: verify that icinga2 package is installed
192-
# yum:
193-
# name: icinga2
194-
# state: present
195-
# when: ansible_os_family == 'RedHat'
196-
197-
# - name: verify that icinga2 package is installed for Debian based systems
198-
# apt:
199-
# name: icinga2
200-
# state: present
201-
# when: ansible_os_family == 'Debian'
202-
203191
- name: verify that icinga2 package is installed
204192
ansible.builtin.package:
205193
name: icinga2

roles/icinga_plugins/defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
icinga2_plugins_basedir:
33
Debian: /usr/lib/nagios
4-
Redhat: /usr/lib64/nagios
4+
RedHat: /usr/lib64/nagios
55

66
icinga2_plugins_pluginsdir: "{{ icinga2_plugins_basedir[ansible_os_family] }}/plugins"
77

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
- name: Converge
3+
hosts: all
4+
collections:
5+
- t_systems_mms.ansible_collection_icinga
6+
pre_tasks:
7+
8+
- name: set name of installation package based on distro
9+
set_fact:
10+
icinga_install_plugins:
11+
- nagios-plugins-all
12+
when:
13+
- ansible_os_family == 'RedHat'
14+
- ansible_facts.distribution_major_version | int is version('8', '<')
15+
16+
- name: set name of installation package based on distro
17+
set_fact:
18+
icinga_install_plugins:
19+
- monitoring-plugins
20+
when: ansible_os_family == 'Debian'
21+
22+
- name: add icinga group
23+
ansible.builtin.group:
24+
name: icinga
25+
state: present
26+
when: ansible_os_family == 'RedHat'
27+
28+
- name: add icinga user with icinga group
29+
ansible.builtin.user:
30+
name: icinga
31+
group: icinga
32+
when: ansible_os_family == 'RedHat'
33+
34+
roles:
35+
- icinga_plugins
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
driver:
5+
name: docker
6+
platforms:
7+
- name: instance
8+
image: "geerlingguy/docker-${MOLECULE_DISTRO}-ansible:latest"
9+
volumes:
10+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
11+
privileged: true
12+
pre_build_image: true
13+
command: ""
14+
provisioner:
15+
name: ansible
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
- name: Prepare
3+
hosts: all
4+
tasks:
5+
- name: install epel repo
6+
yum:
7+
name: epel-release
8+
state: installed
9+
when: ansible_os_family == 'RedHat'
10+
11+
- name: import icinga2 key
12+
command: "rpm --import https://packages.icinga.com/icinga.key"
13+
when: ansible_os_family == 'RedHat'
14+
15+
- name: install icinga2 repo
16+
command: "yum install https://packages.icinga.com/epel/icinga-rpm-release-7-latest.noarch.rpm -y"
17+
when:
18+
- ansible_os_family == 'RedHat'
19+
- ansible_facts.distribution_major_version | int is version('7', '=')
20+
21+
- name: install icinga2 repo
22+
command: "yum install https://packages.icinga.com/epel/icinga-rpm-release-8-latest.noarch.rpm -y"
23+
when:
24+
- ansible_os_family == 'RedHat'
25+
- ansible_facts.distribution_major_version | int is version('8', '=')
26+
27+
- name: install icinga2 basic packages
28+
apt:
29+
name: gnupg
30+
state: present
31+
update_cache: true
32+
when: ansible_os_family == 'Debian'
33+
34+
- name: add icinga2 repo key
35+
apt_key:
36+
url: "http://packages.icinga.com/icinga.key"
37+
state: present
38+
when: ansible_os_family == 'Debian'
39+
40+
- name: add icinga2 repository on debian 11
41+
apt_repository:
42+
repo: "{{ item }}"
43+
state: present
44+
update_cache: true
45+
with_items:
46+
- deb http://packages.icinga.com/debian icinga-bullseye main
47+
- deb-src http://packages.icinga.com/debian icinga-bullseye main
48+
when:
49+
- ansible_os_family == 'Debian'
50+
- ansible_facts.distribution_major_version | int is version('11', '=')
51+
52+
- name: install icinga2 build dependencies
53+
apt:
54+
pkg: "icinga2"
55+
state: "build-dep"
56+
update_cache: true
57+
when: ansible_os_family == 'Debian'
58+
59+
- name: install icinga2 basic packages
60+
apt:
61+
name: "icinga2"
62+
state: "present"
63+
update_cache: true
64+
when: ansible_os_family == 'Debian'
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
- name: Verify
3+
hosts: all
4+
tasks:
5+
- name: set name of installation package based on distro
6+
set_fact:
7+
icinga_install_plugins:
8+
- nagios-plugins-all
9+
when:
10+
- ansible_os_family == 'RedHat'
11+
- ansible_facts.distribution_major_version | int is version('8', '<')
12+
13+
- name: set name of installation package based on distro
14+
set_fact:
15+
icinga_install_plugins:
16+
- monitoring-plugins
17+
when: ansible_os_family == 'Debian'
18+
19+
- name: include default vars from icinga_plugins roles
20+
include_vars:
21+
file: ../../defaults/main.yml
22+
23+
- name: verify that plugin dir exists
24+
file:
25+
path: "{{ icinga2_plugins_pluginsdir }}"
26+
state: directory
27+
register: result_plugin_dir
28+
29+
- name: validate plugin dir exists on system
30+
assert:
31+
that:
32+
- "result_plugin_dir.state == 'directory'"
33+
- "result_plugin_dir.mode == '0755'"
34+
- "result_plugin_dir.owner == 'root'"
35+
- "result_plugin_dir.group == 'root'"
36+
37+
- name: search for all files in plugins directory
38+
ansible.builtin.find:
39+
paths: "{{ icinga2_plugins_pluginsdir }}"
40+
recurse: yes
41+
file_type: file
42+
register: files_in_plugins_dir
43+
check_mode: no
44+
45+
- name: validate plugins belongs to the right user for Redhat based systems
46+
assert:
47+
that:
48+
- "item.pw_name == 'icinga'"
49+
- "item.gr_name == 'icinga'"
50+
loop: "{{ files_in_plugins_dir.files }}"
51+
when: ansible_os_family == 'RedHat'
52+
53+
- name: validate plugins belongs to the right user for Debian based systems
54+
assert:
55+
that:
56+
- "item.pw_name == 'nagios'"
57+
- "item.gr_name == 'nagios'"
58+
loop: "{{ files_in_plugins_dir.files }}"
59+
when: ansible_os_family == 'Debian'
60+
61+
- name: verify that package is installed
62+
package:
63+
name: "{{ icinga_install_plugins }}"
64+
state: present
65+
register: result_installation
66+
when:
67+
- icinga_install_plugins is defined
68+
69+
- name: validate package is installed
70+
assert:
71+
that:
72+
- "result_installation is not changed"
73+
when:
74+
- icinga_install_plugins is defined

roles/icinga_plugins/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
when:
3636
- icinga_install_plugins is defined
3737
- icinga_install_plugins | length > 0
38-
- ansible_facts.os_family == "RedHat" and ansible_facts.distribution_major_version | int is version('7', "=") or ansible_facts.os_family == "Debian"
38+
- (ansible_facts.os_family == "RedHat" and ansible_facts.distribution_major_version | int is version('7', "=")) or ansible_facts.os_family == "Debian"
3939

4040
- name: copy icinga plugins to target node
4141
ansible.builtin.copy:

0 commit comments

Comments
 (0)