Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add object Dependency #65

Merged
merged 11 commits into from
Nov 29, 2021
19 changes: 18 additions & 1 deletion doc/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ icinga2_objects:
- host.address
```

#### Service Apply for
#### Service Apply for

```
[...]
Expand Down Expand Up @@ -415,3 +415,20 @@ icinga2_objects:
-S:
set_if: $http_ssl$
```

#### Dependency

```
- name: dependency-to-host
type: Dependency
apply: true
apply_target: Host
file: zones.d/main/dependencies.conf
parent_host_name: router.localdomain
disable_checks: true
disable_notifications: true
states:
- Up
assign:
- host.name == agent.localdomain
```
12 changes: 12 additions & 0 deletions molecule/default/host_vars/icinga-default.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
icinga2_objects:
icinga-default:
- name: dependency-test
type: Dependency
file: zones.d/main/dependencies.conf
apply: true
apply_target: Host
parent_host_name: agent.localdomain
disable_checks: true
disable_notifications: true
states:
- Up
assign:
- host.name == test.localdomain
- name: agent.localdomain
type: Endpoint
file: zones.d/main/hosts/agent.localdomain.conf
Expand Down
17 changes: 17 additions & 0 deletions molecule/default/tests/integration/test_dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def test_icinga2_object_host(host):
i2_file = host.file("/etc/icinga2/zones.d/main/dependencies.conf")
print(i2_file.content_string)
assert i2_file.is_file
assert i2_file.contains('apply Dependency "dependency-test" to Host {')
assert i2_file.contains('disable_checks = true')
assert i2_file.contains('states = [ Up, ]\n')
assert i2_file.contains('parent_host_name = "agent.localdomain"')
assert i2_file.contains('assign where host.name == "test.localdomain"')
if host.system_info.distribution == 'centos':
assert i2_file.user == "icinga"
assert i2_file.group == "icinga"
assert i2_file.mode == 0o644
if host.system_info.distribution == 'debian':
assert i2_file.user == "nagios"
assert i2_file.group == "nagios"
assert i2_file.mode == 0o644
44 changes: 44 additions & 0 deletions plugins/modules/icinga2_dependency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/python

from ansible.module_utils.basic import AnsibleModule

def main():
module = AnsibleModule(
supports_check_mode=True,
argument_spec = dict(
state = dict(default='present', choices=['present', 'absent']),
name = dict(required=True),
order = dict(default=10, type='int'),
file = dict(required=True, type='str'),
template = dict(default=False, type='bool'),
imports = dict(default=list(), type='list', elements='str'),
apply = dict(default=False, type='bool'),
apply_target = dict(type='str'),
parent_host_name = dict(type='str'),
parent_service_name = dict(type='str'),
child_host_name = dict(type='str'),
child_service_name = dict(type='str'),
disable_checks = dict(type='bool'),
disable_notifications = dict(type='bool'),
ignore_soft_states = dict(type='bool'),
period = dict(type='str'),
states = dict(type='list', elements='str'),
assign = dict(default=list(), type='list', elements='str'),
ignore = dict(default=list(), type='list', elements='str'),
)
)

args = module.params
name = args.pop('name')
order = args.pop('order')
state = args.pop('state')
file = args.pop('file')
template = args.pop('template')
imports = args.pop('imports')
apply = args.pop('apply')
apply_target = args.pop('apply_target')

module.exit_json(changed=False, args=args, name=name, order=str(order), state=state, file=file, template=template, imports=imports, apply=apply, apply_target=apply_target)

if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions roles/icinga2/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ icinga2_object_types:
- IcingaApplication
- ApiUser
- CheckCommand
- Dependency
- Notification
- NotificationCommand
- User
Expand Down