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

67 lines
1.8 KiB
Django/Jinja

# {{ ansible_managed }}
{% for name, host in icinga2_hosts.items() %}
object Host "{{ name }}" {
{% if host.template is defined %}
import "{{ host.template }}"
{% endif %}
{% if host.address is defined %}
address = "{{ host.address }}"
{% endif %}
{% if host.address6 is defined %}
address6 = "{{ host.address6 }}"
{% endif %}
{% if host.zone is defined %}
zone = "{{ host.zone }}"
{% endif %}
{% if host.options is defined %}
{% for var, value in host.options.items() %}
{% if value is sameas True %}
{{ var }} = true
{% elif value is sameas False %}
{{ var }} = false
{% elif value is mapping %}
{% for name, config in value.items() %}
{{ var }}["{{ name }}"] = {
{% for option, v in config.items() %}
{{ option }} = {% if v is number %}{{ v }}{% else %}"{{ v }}"{% endif %}
{% endfor %}
}
{% endfor %}
{% elif value is iterable and not value is string %}
{{ var }} = [ "{{ value|join('", "') }}" ]
{% elif value is number or value|regex_search('^[0-9]+(s|m|h|d)$') %}
{{ var }} = {{ value }}
{% else %}
{{ var }} = "{{ value }}"
{% endif %}
{% endfor %}
{% endif %}
{% if host.vars is defined %}
{% for var, value in host.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 }}"{% endif %}
{% 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 }}"
{% endif %}
{% endfor %}
{% endif %}
}
{% endfor %}