Skip to content

Commit

Permalink
Merge pull request #81 from BenjaminBoehm/main
Browse files Browse the repository at this point in the history
Make hostname for Icinga agent configurable
  • Loading branch information
schurzi authored May 27, 2024
2 parents 82faeba + 9dc1ad3 commit 9d13a58
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion roles/icinga_agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ This role installs and configures the icinga agent.
| icinga_agent_package | yes | icinga2 | installs icinga2 package
| icinga_agent_registration | yes | false | used to register your installed icinga agent against your icinga master
| icinga_agent_enable_features | no | | config files for extra features you can use along with icinga. If you add for example api.conf to the variable the feature will be active in your icinga instance
| icinga_agent_ca_host | no | | your master intance (f.e: master0-example.de)
| icinga_agent_ca_host | no | | your master instance (f.e: master0-example.de)
| icinga_agent_ca_host_icinga_port | no | 5665 | Icinga agent port
| icinga_agent_salt | no | | used to hash password
| icinga_agent_hostname | no | "{{ ansible_hostname }}" | define hostname (icinga satellites require this to be set to `ansible_fqdn` or some other usable FQDN)
| icinga_agent_custom_features_template_path | no | | define custom feature file (f.e. {{ playbook_dir }}/icinga_custom_templates/*)
| icinga_agent_constants[RedHat, Debian] | yes | const PluginDir = "/usr/lib64/nagios/plugins"<br> const PluginContribDir = "/usr/lib64/nagios/plugins"<br> const ManubulonPluginDir = "/usr/lib64/nagios/plugins"<br> const ZoneName = "{{ ansible_hostname }}"<br> const NodeName = "{{ ansible_hostname }}"<br> const TicketSalt = "" | define content for config file constants.conf, depending on the OS family |
| icinga_agent_api_conf | yes | accept_config = true<br>accept_commands = true | define content for feature file api.conf |
Expand Down
9 changes: 5 additions & 4 deletions roles/icinga_agent/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
icinga_agent_package: icinga2
icinga_agent_registration: false
icinga_agent_ca_host_icinga_port: 5665
icinga_agent_hostname: "{{ ansible_hostname }}"
icinga_agent_constants:
RedHat: |
const PluginDir = "/usr/lib64/nagios/plugins"
const PluginContribDir = "/usr/lib64/nagios/plugins"
const ManubulonPluginDir = "/usr/lib64/nagios/plugins"
const ZoneName = "{{ ansible_hostname }}"
const NodeName = "{{ ansible_hostname }}"
const ZoneName = "{{ icinga_agent_hostname }}"
const NodeName = "{{ icinga_agent_hostname }}"
const TicketSalt = ""
Debian: |
const PluginDir = "/usr/lib/nagios/plugins"
const PluginContribDir = "/usr/lib/nagios/plugins"
const ManubulonPluginDir = "/usr/lib/nagios/plugins"
const ZoneName = "{{ ansible_hostname }}"
const NodeName = "{{ ansible_hostname }}"
const ZoneName = "{{ icinga_agent_hostname }}"
const NodeName = "{{ icinga_agent_hostname }}"
const TicketSalt = ""
icinga_agent_api_conf: |
accept_config = true
Expand Down
18 changes: 9 additions & 9 deletions roles/icinga_agent/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

- name: Generate ticket and save it as a variable
ansible.builtin.command: >
/usr/sbin/icinga2 pki ticket --cn {{ ansible_hostname }} --salt {{ icinga_agent_salt }}
/usr/sbin/icinga2 pki ticket --cn {{ icinga_agent_hostname }} --salt {{ icinga_agent_salt }}
environment:
LD_LIBRARY_PATH: /usr/lib64
register: ticket
Expand All @@ -102,16 +102,16 @@

- name: Create certificate
ansible.builtin.command: >
/usr/sbin/icinga2 pki new-cert --cn {{ ansible_hostname }}
--key /var/lib/icinga2/certs/{{ ansible_hostname }}.key
--cert /var/lib/icinga2/certs/{{ ansible_hostname }}.crt
/usr/sbin/icinga2 pki new-cert --cn {{ icinga_agent_hostname }}
--key /var/lib/icinga2/certs/{{ icinga_agent_hostname }}.key
--cert /var/lib/icinga2/certs/{{ icinga_agent_hostname }}.crt
args:
creates: /var/lib/icinga2/certs/{{ ansible_hostname }}.crt
creates: /var/lib/icinga2/certs/{{ icinga_agent_hostname }}.crt

- name: Save the icinga master's certificate to the host
ansible.builtin.command: >
/usr/sbin/icinga2 pki save-cert --key /var/lib/icinga2/certs/{{ ansible_hostname }}.key
--cert /var/lib/icinga2/certs/{{ ansible_hostname }}.crt
/usr/sbin/icinga2 pki save-cert --key /var/lib/icinga2/certs/{{ icinga_agent_hostname }}.key
--cert /var/lib/icinga2/certs/{{ icinga_agent_hostname }}.crt
--trustedcert /var/lib/icinga2/certs/trusted-master.crt
--host {{ icinga_agent_ca_host }}
args:
Expand All @@ -121,8 +121,8 @@
ansible.builtin.command: >
/usr/sbin/icinga2 pki request --host {{ icinga_agent_ca_host }}
--port {{ icinga_agent_ca_host_icinga_port }}
--ticket {{ ticket.stdout }} --key /var/lib/icinga2/certs/{{ ansible_hostname }}.key
--cert /var/lib/icinga2/certs/{{ ansible_hostname }}.crt
--ticket {{ ticket.stdout }} --key /var/lib/icinga2/certs/{{ icinga_agent_hostname }}.key
--cert /var/lib/icinga2/certs/{{ icinga_agent_hostname }}.crt
--trustedcert /var/lib/icinga2/certs/trusted-master.crt --ca /var/lib/icinga2/certs/ca.crt
args:
creates: /var/lib/icinga2/certs/ca.crt
Expand Down

0 comments on commit 9d13a58

Please sign in to comment.