|
| 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 |
0 commit comments