You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/role-icinga2/objects.md
+41Lines changed: 41 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,8 @@ The `type` will be the original Icinga 2 object types, a list of all can be foun
22
22
When defining `icinga2_objects` as a host specific variable (hostvars/groupvars) you can define the variable as a dictionary. Each dictionary key represents the host on which the key's value will be deployed as configuration.<br>
23
23
Alternatively you can define `icinga2_objects` as a list which results in the configuration being deployed on just the host for which the variable is defined.
24
24
25
+
Because it's easily overlooked, here are few more words of clarification: The first example shows variables of the host `webserver.example.org` but the `icinga2_objects` variable includes `host.example.org` and an extra level of indentation. This means that the following configuration will not be deployed on `webserver.example.org` but on `host.example.org`. This is especially useful when defining host objects on agents but "sending" them to the central nodes.
26
+
25
27
Example defining the variable within hostvars as a dictionary (inventory entry):
26
28
27
29
```yaml
@@ -40,6 +42,45 @@ webserver.example.org:
40
42
41
43
This way you can use some host's variables (like `ansible_host`) to deploy configuration on another host (in this case `host.example.org`).
42
44
45
+
You can use this variant within a playbook where `host.example.org` is your central Icinga 2 instance. Run it on all agents. They will collect their local facts and the central system `host.example.org` will receive host objects for each agent. This approach will only work if you run the play simultanously on your agents and on your central system.
46
+
47
+
```
48
+
- hosts: icinga2_main:icinga2_agents
49
+
collections:
50
+
- netways.icinga
51
+
pre_tasks:
52
+
# This assumes that agents don't have 'icinga2_objects' defined at hostvars level
53
+
# 'set_fact' will override them!
54
+
- name: Add agent hosts to Icinga 2 objects
55
+
when: inventory_hostname in groups["icinga2_agents"]
56
+
set_fact:
57
+
icinga2_objects:
58
+
# Name of the central system on which to deploy the given objects
0 commit comments