feat: add options in hosts

This commit is contained in:
Adrien Waksberg 2023-11-06 08:04:39 +01:00
parent a0efb0d8db
commit eaf0b7e0c7
2 changed files with 27 additions and 0 deletions

View file

@ -8,6 +8,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
### Added ### Added
- add dependencies - add dependencies
- add options in host
### Fixed ### Fixed

View file

@ -2,7 +2,9 @@
{% for name, host in icinga2_hosts.items() %} {% for name, host in icinga2_hosts.items() %}
object Host "{{ name }}" { object Host "{{ name }}" {
{% if host.template is defined %}
import "{{ host.template }}" import "{{ host.template }}"
{% endif %}
{% if host.address is defined %} {% if host.address is defined %}
address = "{{ host.address }}" address = "{{ host.address }}"
{% endif %} {% endif %}
@ -12,6 +14,30 @@ object Host "{{ name }}" {
{% if host.zone is defined %} {% if host.zone is defined %}
zone = "{{ host.zone }}" zone = "{{ host.zone }}"
{% endif %} {% 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 %} {% if host.vars is defined %}
{% for var, value in host.vars.items() %} {% for var, value in host.vars.items() %}