-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add molecule for role icinga_plugins (#18)
* added Molecule tests for centos7, rocky linux 8 and rocky linux 8 Co-authored-by: xFuture603 <[email protected]> Co-authored-by: Christoph <[email protected]>
- Loading branch information
1 parent
ae1d36d
commit 5ce7c5e
Showing
8 changed files
with
199 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
- name: Converge | ||
hosts: all | ||
collections: | ||
- t_systems_mms.ansible_collection_icinga | ||
pre_tasks: | ||
|
||
- name: set name of installation package based on distro | ||
set_fact: | ||
icinga_install_plugins: | ||
- nagios-plugins-all | ||
when: | ||
- ansible_os_family == 'RedHat' | ||
- ansible_facts.distribution_major_version | int is version('8', '<') | ||
|
||
- name: set name of installation package based on distro | ||
set_fact: | ||
icinga_install_plugins: | ||
- monitoring-plugins | ||
when: ansible_os_family == 'Debian' | ||
|
||
- name: add icinga group | ||
ansible.builtin.group: | ||
name: icinga | ||
state: present | ||
when: ansible_os_family == 'RedHat' | ||
|
||
- name: add icinga user with icinga group | ||
ansible.builtin.user: | ||
name: icinga | ||
group: icinga | ||
when: ansible_os_family == 'RedHat' | ||
|
||
roles: | ||
- icinga_plugins |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
dependency: | ||
name: galaxy | ||
driver: | ||
name: docker | ||
platforms: | ||
- name: instance | ||
image: "geerlingguy/docker-${MOLECULE_DISTRO}-ansible:latest" | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:rw | ||
privileged: true | ||
pre_build_image: true | ||
command: "" | ||
provisioner: | ||
name: ansible |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
- name: Prepare | ||
hosts: all | ||
tasks: | ||
- name: install epel repo | ||
yum: | ||
name: epel-release | ||
state: installed | ||
when: ansible_os_family == 'RedHat' | ||
|
||
- name: import icinga2 key | ||
command: "rpm --import https://packages.icinga.com/icinga.key" | ||
when: ansible_os_family == 'RedHat' | ||
|
||
- name: install icinga2 repo | ||
command: "yum install https://packages.icinga.com/epel/icinga-rpm-release-7-latest.noarch.rpm -y" | ||
when: | ||
- ansible_os_family == 'RedHat' | ||
- ansible_facts.distribution_major_version | int is version('7', '=') | ||
|
||
- name: install icinga2 repo | ||
command: "yum install https://packages.icinga.com/epel/icinga-rpm-release-8-latest.noarch.rpm -y" | ||
when: | ||
- ansible_os_family == 'RedHat' | ||
- ansible_facts.distribution_major_version | int is version('8', '=') | ||
|
||
- name: install icinga2 basic packages | ||
apt: | ||
name: gnupg | ||
state: present | ||
update_cache: true | ||
when: ansible_os_family == 'Debian' | ||
|
||
- name: add icinga2 repo key | ||
apt_key: | ||
url: "http://packages.icinga.com/icinga.key" | ||
state: present | ||
when: ansible_os_family == 'Debian' | ||
|
||
- name: add icinga2 repository on debian 11 | ||
apt_repository: | ||
repo: "{{ item }}" | ||
state: present | ||
update_cache: true | ||
with_items: | ||
- deb http://packages.icinga.com/debian icinga-bullseye main | ||
- deb-src http://packages.icinga.com/debian icinga-bullseye main | ||
when: | ||
- ansible_os_family == 'Debian' | ||
- ansible_facts.distribution_major_version | int is version('11', '=') | ||
|
||
- name: install icinga2 build dependencies | ||
apt: | ||
pkg: "icinga2" | ||
state: "build-dep" | ||
update_cache: true | ||
when: ansible_os_family == 'Debian' | ||
|
||
- name: install icinga2 basic packages | ||
apt: | ||
name: "icinga2" | ||
state: "present" | ||
update_cache: true | ||
when: ansible_os_family == 'Debian' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
- name: Verify | ||
hosts: all | ||
tasks: | ||
- name: set name of installation package based on distro | ||
set_fact: | ||
icinga_install_plugins: | ||
- nagios-plugins-all | ||
when: | ||
- ansible_os_family == 'RedHat' | ||
- ansible_facts.distribution_major_version | int is version('8', '<') | ||
|
||
- name: set name of installation package based on distro | ||
set_fact: | ||
icinga_install_plugins: | ||
- monitoring-plugins | ||
when: ansible_os_family == 'Debian' | ||
|
||
- name: include default vars from icinga_plugins roles | ||
include_vars: | ||
file: ../../defaults/main.yml | ||
|
||
- name: verify that plugin dir exists | ||
file: | ||
path: "{{ icinga2_plugins_pluginsdir }}" | ||
state: directory | ||
register: result_plugin_dir | ||
|
||
- name: validate plugin dir exists on system | ||
assert: | ||
that: | ||
- "result_plugin_dir.state == 'directory'" | ||
- "result_plugin_dir.mode == '0755'" | ||
- "result_plugin_dir.owner == 'root'" | ||
- "result_plugin_dir.group == 'root'" | ||
|
||
- name: search for all files in plugins directory | ||
ansible.builtin.find: | ||
paths: "{{ icinga2_plugins_pluginsdir }}" | ||
recurse: yes | ||
file_type: file | ||
register: files_in_plugins_dir | ||
check_mode: no | ||
|
||
- name: validate plugins belongs to the right user for Redhat based systems | ||
assert: | ||
that: | ||
- "item.pw_name == 'icinga'" | ||
- "item.gr_name == 'icinga'" | ||
loop: "{{ files_in_plugins_dir.files }}" | ||
when: ansible_os_family == 'RedHat' | ||
|
||
- name: validate plugins belongs to the right user for Debian based systems | ||
assert: | ||
that: | ||
- "item.pw_name == 'nagios'" | ||
- "item.gr_name == 'nagios'" | ||
loop: "{{ files_in_plugins_dir.files }}" | ||
when: ansible_os_family == 'Debian' | ||
|
||
- name: verify that package is installed | ||
package: | ||
name: "{{ icinga_install_plugins }}" | ||
state: present | ||
register: result_installation | ||
when: | ||
- icinga_install_plugins is defined | ||
|
||
- name: validate package is installed | ||
assert: | ||
that: | ||
- "result_installation is not changed" | ||
when: | ||
- icinga_install_plugins is defined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters