ansible-role-icinga2/templates/services.conf.j2

48 lines
1.4 KiB
Text
Raw Normal View History

2021-01-03 15:10:04 +00:00
# {{ ansible_managed }}
{% for name, service in icinga2_services.items() %}
apply Service "{{ name }}" {
import "{{ service.import|default('generic-service') }}"
check_command = "{{ service.check_command }}"
assign where {{ service.assign }}
{% if service.options is defined %}
{% for option, value in service.options.items() %}
{% if value is sameas True %}
{{ option }} = true
{% elif value is sameas False %}
{{ option }} = false
{% elif value is number or value|regex_search('^[0-9]+(s|m|h|d)$') %}
{{ option }} = {{ value }}
{% else %}
{{ option }} = "{{ value }}"
{% endif %}
{% endfor %}
{% endif %}
{% if service.vars is defined %}
{% for var, value in service.vars.items() %}
{% if value is sameas True %}
vars.{{ var }} = true
{% elif value is sameas False %}
vars.{{ var }} = false
{% elif value is mapping %}
{% for name, config in value.items() %}
vars.{{ var }}["{{ name }}"] = {
{% for option, v in config.items() %}
{{ option }} = {% if v is number %}{{ v }}{% else %}"{{ v|replace('\n', ' ')|trim }}"{% endif %}
2021-01-03 15:10:04 +00:00
{% endfor %}
}
{% endfor %}
{% elif value is iterable and not value is string %}
vars.{{ var }} = [ "{{ value|join(', "') }}" ]
{% elif value is number or value|regex_search('^[0-9]+(s|m|h|d)$') %}
vars.{{ var }} = {{ value }}
{% else %}
vars.{{ var }} = "{{ value|replace('\n', ' ')|trim }}"
{% endif %}
2021-01-03 15:10:04 +00:00
{% endfor %}
{% endif %}
}
{% endfor %}