icinga_agent: new role to enroll an agent

This commit is contained in:
Markus 2024-03-01 22:35:06 +01:00
parent 0e9d3092e6
commit 34b1d83233
2 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,4 @@
---
icinga_user: nagios
icinga_group: nagios

View File

@ -0,0 +1,58 @@
---
- name: Install icinga
apt: name=icinga2
- name: Check if client is already enrolled
stat:
path: /var/lib/icinga2/certs/{{ ansible_fqdn }}.crt
register: cert_file
- name: Enroll agent on master server
block:
- name: Ensure certificate directory exists
file:
path: /var/lib/icinga2/certs
state: directory
owner: "{{ icinga_user }}"
group: "{{ icinga_group }}"
- name: Copy certificate from master
fetch:
src: /var/lib/icinga2/certs/{{ icinga_server }}.crt
dest: /tmp/{{ icinga_server }}.crt
flat: true
delegate_to: "{{ icinga_server }}"
- name: Copy certificate to host
copy:
src: /tmp/{{ icinga_server }}.crt
dest: /var/lib/icinga2/certs/{{ icinga_server }}.crt
owner: "{{ icinga_user }}"
group: "{{ icinga_group }}"
- name: Get ticket from master
shell: "icinga2 pki ticket --cn {{ ansible_fqdn }}"
register: "icinga_ticket"
changed_when: "False"
delegate_to: "{{ icinga_server }}"
- name: Setup node
command:
argv:
- icinga2
- node
- setup
- --ticket
- "{{ icinga_ticket.stdout | trim }}"
- --endpoint
- "{{ icinga_server }}"
- --zone
- "{{ ansible_fqdn }}"
- --parent_host
- "{{ icinga_server }}"
- --trustedcert
- "/var/lib/icinga2/certs/{{ icinga_server }}.crt"
- --accept-commands
- --accept-config
when: not cert_file.stat.exists