EvoBSD/roles/nagios-nrpe/tasks/main.yml

160 lines
4.1 KiB
YAML
Raw Normal View History

2022-10-19 18:23:54 +02:00
# yamllint disable rule:line-length
2018-12-28 11:23:49 +01:00
---
- name: "Install nrpe"
community.general.openbsd_pkg:
name:
- nrpe--
2018-12-28 11:23:49 +01:00
state: present
tags:
- nagios-nrpe
2018-12-28 11:23:49 +01:00
- name: "Install monitoring packages"
community.general.openbsd_pkg:
name:
- monitoring-plugins
- check_bioctl
2018-12-28 11:23:49 +01:00
state: present
tags:
- nagios-nrpe
2018-12-28 11:23:49 +01:00
- name: "Create nrpe.d dir"
ansible.builtin.file:
2018-12-28 11:23:49 +01:00
path: /etc/nrpe.d
state: directory
owner: root
group: wheel
mode: "0755"
tags:
- nagios-nrpe
2018-12-28 11:23:49 +01:00
- name: "Include nrpe.d dir in nrpe.cfg"
ansible.builtin.lineinfile:
2018-12-28 11:23:49 +01:00
dest: /etc/nrpe.cfg
line: 'include_dir=/etc/nrpe.d'
create: true
tags:
- nagios-nrpe
2018-12-28 11:23:49 +01:00
- name: "Check if nrpe service exists, for usage in check_mode"
stat:
path: /etc/rc.d/nrpe
register: nrpe_exists
- name: "Custom configuration is present"
ansible.builtin.blockinfile:
block: "{{ lookup('template', 'evolix_bsd.cfg.j2') }}"
path: /etc/nrpe.d/evolix.cfg
marker: "## {mark} ANSIBLE MANAGED BLOCK : Custom NRPE configuration file from EvoBSD"
2022-10-19 18:23:54 +02:00
create: true
mode: "0644"
insertbefore: BOF
2018-12-28 11:23:49 +01:00
notify: restart nrpe
tags:
- nagios-nrpe
2018-12-28 11:23:49 +01:00
- name: "Fetch nrpe config content"
ansible.builtin.command: 'grep "allowed_hosts=" /etc/nrpe.d/evolix.cfg'
check_mode: false
register: nrpe_config_content
failed_when: false
changed_when: false
tags:
- nagios-nrpe
- name: "Allow NRPE hosts - if no allowed_hosts configured"
ansible.builtin.lineinfile:
dest: /etc/nrpe.d/evolix.cfg
insertbefore: BOF
regex: "allowed_hosts={{ nagios_nrpe_allowed_hosts | join(',') }}"
line: 'allowed_hosts={{ nagios_nrpe_allowed_hosts | join(",") }}'
create: true
mode: "0644"
when: nrpe_config_content.rc != 0
tags:
- nagios-nrpe
- name: "Allow NRPE hosts - if allowed_hosts already configured : keep added IP"
ansible.builtin.lineinfile:
dest: /etc/nrpe.d/evolix.cfg
2022-10-19 18:23:54 +02:00
backrefs: true
insertbefore: BOF
regex: "allowed_hosts={{ nagios_nrpe_allowed_hosts | join(',') }}(.*)*"
line: 'allowed_hosts={{ nagios_nrpe_allowed_hosts | join(",") }}\1'
create: true
mode: "0644"
when: nrpe_config_content.rc == 0
tags:
- nagios-nrpe
- name: "Allow NRPE hosts - add comment"
ansible.builtin.lineinfile:
dest: /etc/nrpe.d/evolix.cfg
insertbefore: BOF
line: "# Allowed IPs"
create: true
mode: "0644"
tags:
- nagios-nrpe
- name: "Create nrpe plugins dir"
ansible.builtin.file:
2020-10-14 16:35:17 +02:00
path: /usr/local/libexec/nagios/plugins/
state: directory
owner: root
group: wheel
mode: "0755"
tags:
- nagios-nrpe
2020-10-14 16:35:17 +02:00
- name: "Nagios plugins are installed"
ansible.builtin.copy:
src: plugins_bsd/{{ item.name }}
dest: /usr/local/libexec/nagios/plugins/{{ item.name }}
2018-12-28 11:23:49 +01:00
owner: root
group: wheel
mode: "0755"
force: "{{ item.force }}"
with_items:
- {name: 'check_carp_if', force: true}
- {name: 'check_connections_state.sh', force: false}
- {name: 'check_ipsecctl.sh', force: false}
- {name: 'check_ipsecctl_critiques.sh', force: false}
- {name: 'check_openbgpd', force: true}
- {name: 'check_openvpn', force: false}
- {name: 'check_openvpn.pl', force: true}
- {name: 'check_ospfd_simple', force: true}
2020-10-13 12:02:48 +02:00
- {name: 'check_packetfilter.sh', force: true}
- {name: 'check_pf_states', force: false}
- {name: 'check_mailq.pl', force: true}
2022-03-31 11:57:45 +02:00
- {name: 'check_dhcp_pool', force: false}
- {name: 'check_dhcpd.sh', force: false}
2023-06-26 16:27:50 +02:00
- {name: 'check_ipmi_sensor', force: true}
2018-12-28 11:23:49 +01:00
notify: restart nrpe
tags:
- nagios-nrpe
- nagios-nrpe-utils
2018-12-28 11:23:49 +01:00
- name: "Nagios plugins are installed - template"
ansible.builtin.template:
src: plugins_bsd/{{ item.name }}.j2
dest: /usr/local/libexec/nagios/plugins/{{ item.name }}
2018-12-28 11:23:49 +01:00
owner: root
group: wheel
mode: "0755"
force: "{{ item.force }}"
2018-12-28 11:23:49 +01:00
with_items:
- {name: 'check_free_mem.sh', force: true}
2018-12-28 11:23:49 +01:00
notify: restart nrpe
tags:
- nagios-nrpe
- nagios-nrpe-utils
2018-12-28 11:23:49 +01:00
- name: "Starting and enabling nrpe"
ansible.builtin.service:
2018-12-28 11:23:49 +01:00
name: nrpe
enabled: true
2018-12-28 11:23:49 +01:00
state: started
when: nrpe_exists.stat.exists
tags:
- nagios-nrpe