-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Description
Hi all
When installing an Icinga2 Agent for the first time, it needs the CA certificate from the Icinga2 Master. Usually the Agent can establish a session on port 5665. And this task in roles/icinga2/tasks/features/api.yml
saves that certificate:
- name: save trusted-master.crt
shell: >-
icinga2 pki save-cert
--host "{{ icinga2_ca_host }}"
--port "{{ icinga2_ca_host_port | default('5665') }}"
--trustedcert "{{ icinga2_cert_path }}/trusted-master.crt"
when: icinga2_ca_host != 'none'
register: _trusted_master_cert
However, in our setup, communication on port 5665 to the Icinga2 Master is blocked. So the Icinga2 Master has to establish a connection to the Agent. But how can I get the CA cert to the Agent? The task above doesn't work because the Agent can't establish the connection.
I was able to make it work with the following workaround, but I'm not sure if there's a better way...
# NOTE Doesn't work because we have no connection from agent to master
# - name: save trusted-master.crt
# shell: >-
# icinga2 pki save-cert
# --host "{{ icinga2_ca_host }}"
# --port "{{ icinga2_ca_host_port | default('5665') }}"
# --trustedcert "{{ icinga2_cert_path }}/trusted-master.crt"
# when: icinga2_ca_host != 'none'
# register: _trusted_master_cert
# Workaround
# Connect to Master, slurp the CA certificate and save it
- name: Fetch CA certificate content from the delegated host
slurp:
src: /var/lib/icinga2/ca/ca.crt
delegate_to: "{{ icinga2_delegate_host | default(icinga2_ca_host) }}"
register: ca_cert_content_slurped
when: icinga2_ca_host != 'none'
- name: Decode and save the CA certificate content as a fact
set_fact:
ca_cert_content: "{{ ca_cert_content_slurped['content'] | b64decode }}"
when: icinga2_ca_host != 'none' and ca_cert_content_slurped is defined
- name: Save the CA certificate content to /var/lib/icinga2/certs/ca.crt on the original host
copy:
dest: /var/lib/icinga2/certs/ca.crt
content: "{{ ca_cert_content }}"
owner: nagios
group: nagios
mode: '0644'
when: icinga2_ca_host != 'none' and ca_cert_content is defined
Is there a better way to achieve that? Or could this be integrated into the collection?
Metadata
Metadata
Assignees
Labels
No labels