Skip to content

Commit 9d13a58

Browse files
authored
Merge pull request #81 from BenjaminBoehm/main
Make hostname for Icinga agent configurable
2 parents 82faeba + 9dc1ad3 commit 9d13a58

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

roles/icinga_agent/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ This role installs and configures the icinga agent.
88
| icinga_agent_package | yes | icinga2 | installs icinga2 package
99
| icinga_agent_registration | yes | false | used to register your installed icinga agent against your icinga master
1010
| 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
11-
| icinga_agent_ca_host | no | | your master intance (f.e: master0-example.de)
11+
| icinga_agent_ca_host | no | | your master instance (f.e: master0-example.de)
1212
| icinga_agent_ca_host_icinga_port | no | 5665 | Icinga agent port
1313
| icinga_agent_salt | no | | used to hash password
14+
| icinga_agent_hostname | no | "{{ ansible_hostname }}" | define hostname (icinga satellites require this to be set to `ansible_fqdn` or some other usable FQDN)
1415
| icinga_agent_custom_features_template_path | no | | define custom feature file (f.e. {{ playbook_dir }}/icinga_custom_templates/*)
1516
| 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 |
1617
| icinga_agent_api_conf | yes | accept_config = true<br>accept_commands = true | define content for feature file api.conf |

roles/icinga_agent/defaults/main.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
icinga_agent_package: icinga2
33
icinga_agent_registration: false
44
icinga_agent_ca_host_icinga_port: 5665
5+
icinga_agent_hostname: "{{ ansible_hostname }}"
56
icinga_agent_constants:
67
RedHat: |
78
const PluginDir = "/usr/lib64/nagios/plugins"
89
const PluginContribDir = "/usr/lib64/nagios/plugins"
910
const ManubulonPluginDir = "/usr/lib64/nagios/plugins"
10-
const ZoneName = "{{ ansible_hostname }}"
11-
const NodeName = "{{ ansible_hostname }}"
11+
const ZoneName = "{{ icinga_agent_hostname }}"
12+
const NodeName = "{{ icinga_agent_hostname }}"
1213
const TicketSalt = ""
1314
Debian: |
1415
const PluginDir = "/usr/lib/nagios/plugins"
1516
const PluginContribDir = "/usr/lib/nagios/plugins"
1617
const ManubulonPluginDir = "/usr/lib/nagios/plugins"
17-
const ZoneName = "{{ ansible_hostname }}"
18-
const NodeName = "{{ ansible_hostname }}"
18+
const ZoneName = "{{ icinga_agent_hostname }}"
19+
const NodeName = "{{ icinga_agent_hostname }}"
1920
const TicketSalt = ""
2021
icinga_agent_api_conf: |
2122
accept_config = true

roles/icinga_agent/tasks/main.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393

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

103103
- name: Create certificate
104104
ansible.builtin.command: >
105-
/usr/sbin/icinga2 pki new-cert --cn {{ ansible_hostname }}
106-
--key /var/lib/icinga2/certs/{{ ansible_hostname }}.key
107-
--cert /var/lib/icinga2/certs/{{ ansible_hostname }}.crt
105+
/usr/sbin/icinga2 pki new-cert --cn {{ icinga_agent_hostname }}
106+
--key /var/lib/icinga2/certs/{{ icinga_agent_hostname }}.key
107+
--cert /var/lib/icinga2/certs/{{ icinga_agent_hostname }}.crt
108108
args:
109-
creates: /var/lib/icinga2/certs/{{ ansible_hostname }}.crt
109+
creates: /var/lib/icinga2/certs/{{ icinga_agent_hostname }}.crt
110110

111111
- name: Save the icinga master's certificate to the host
112112
ansible.builtin.command: >
113-
/usr/sbin/icinga2 pki save-cert --key /var/lib/icinga2/certs/{{ ansible_hostname }}.key
114-
--cert /var/lib/icinga2/certs/{{ ansible_hostname }}.crt
113+
/usr/sbin/icinga2 pki save-cert --key /var/lib/icinga2/certs/{{ icinga_agent_hostname }}.key
114+
--cert /var/lib/icinga2/certs/{{ icinga_agent_hostname }}.crt
115115
--trustedcert /var/lib/icinga2/certs/trusted-master.crt
116116
--host {{ icinga_agent_ca_host }}
117117
args:
@@ -121,8 +121,8 @@
121121
ansible.builtin.command: >
122122
/usr/sbin/icinga2 pki request --host {{ icinga_agent_ca_host }}
123123
--port {{ icinga_agent_ca_host_icinga_port }}
124-
--ticket {{ ticket.stdout }} --key /var/lib/icinga2/certs/{{ ansible_hostname }}.key
125-
--cert /var/lib/icinga2/certs/{{ ansible_hostname }}.crt
124+
--ticket {{ ticket.stdout }} --key /var/lib/icinga2/certs/{{ icinga_agent_hostname }}.key
125+
--cert /var/lib/icinga2/certs/{{ icinga_agent_hostname }}.crt
126126
--trustedcert /var/lib/icinga2/certs/trusted-master.crt --ca /var/lib/icinga2/certs/ca.crt
127127
args:
128128
creates: /var/lib/icinga2/certs/ca.crt

0 commit comments

Comments
 (0)