110 lines
2.7 KiB
YAML
110 lines
2.7 KiB
YAML
- name: Gather installed package facts
|
|
package_facts:
|
|
manager: auto
|
|
|
|
- name: Debug OS family fact
|
|
debug:
|
|
msg: "{{ ansible_facts['os_family'] }} is the OS"
|
|
|
|
- name: Set NRPE package name
|
|
set_fact:
|
|
nrpe_package: >
|
|
{% if ansible_facts['os_family'] == 'Debian' %}
|
|
nagios-nrpe-plugin
|
|
{% elif ansible_facts['os_family'] == 'RedHat' %}
|
|
nagios-plugins-nrpe.x86_64
|
|
{% else %}
|
|
nrpe
|
|
{% endif %}
|
|
register: nrpe_package_set
|
|
|
|
|
|
- name: Set NRPE package name
|
|
set_fact:
|
|
nrpe_installed: "{{ nrpe_package in ansible_facts.packages }}"
|
|
|
|
|
|
- name: Check if nagios NRPE is installed
|
|
debug:
|
|
msg: "NRPE is installed."
|
|
when: nrpe_installed
|
|
|
|
- name: Ensure NRPE is installed (Debian/Ubuntu)
|
|
apt:
|
|
name: "{{ nrpe_package }}"
|
|
state: present
|
|
become: true
|
|
register: nrpe_install_result
|
|
when:
|
|
- ansible_facts['os_family'] == 'Debian'
|
|
- not nrpe_installed
|
|
|
|
- name: Ensure NRPE is installed (RedHat/CentOS)
|
|
yum:
|
|
name: "{{ nrpe_package }}"
|
|
state: present
|
|
become: yes
|
|
register: nrpe_install_result
|
|
when:
|
|
- ansible_facts['os_family'] == 'RedHat'
|
|
- not nrpe_installed
|
|
|
|
- name: Ensure NRPE is installed (FreeBSD)
|
|
ansible.builtin.pkgng:
|
|
name: "{{ nrpe_package }}"
|
|
state: present
|
|
become: yes
|
|
register: nrpe_install_result
|
|
when:
|
|
- ansible_facts['os_family'] == 'FreeBSD'
|
|
- not nrpe_installed
|
|
|
|
|
|
- name: Set psutil_installed fact if any package name contains "psutil"
|
|
ansible.builtin.set_fact:
|
|
psutil_installed: "{{ (ansible_facts.packages | default({}) | dict2items | map(attribute='key') | select('search','psutil') | list) | length > 0 }}"
|
|
|
|
- name: Debug psutil presence
|
|
ansible.builtin.debug:
|
|
msg: "psutil already installed on host."
|
|
when: psutil_installed
|
|
|
|
- name: Ensure python3-psutil is installed (Debian/Ubuntu)
|
|
ansible.builtin.apt:
|
|
name: python3-psutil
|
|
state: present
|
|
become: yes
|
|
register: psutil_install_result
|
|
when:
|
|
- ansible_facts['os_family'] == 'Debian'
|
|
- not psutil_installed
|
|
|
|
- name: Ensure python3-psutil is installed (RedHat/CentOS)
|
|
ansible.builtin.yum:
|
|
name: python3-psutil
|
|
state: present
|
|
become: yes
|
|
register: psutil_install_result
|
|
when:
|
|
- ansible_facts['os_family'] == 'RedHat'
|
|
- not psutil_installed
|
|
|
|
- name: Ensure psutil is installed (FreeBSD)
|
|
ansible.builtin.pkgng:
|
|
name: python3-psutil
|
|
state: present
|
|
become: yes
|
|
register: psutil_install_result
|
|
when:
|
|
- ansible_facts['os_family'] == 'FreeBSD'
|
|
- not psutil_installed
|
|
|
|
|
|
- name: Deploy custom Nagios/NRPE script
|
|
ansible.builtin.copy:
|
|
src: memory_usage_check.py
|
|
dest: /usr/local/nagios/libexec/my_custom_check.py
|
|
mode: '0755'
|
|
when:
|
|
- nrpe_installed is defined
|
|
- psutil_installed is defined |