host.conf.tmpl 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #
  2. # {{ node_id }}
  3. #
  4. {%- set roles = node_config.get ('roles', [])|sort %}
  5. {%- set sites = node_config.get ('sites', [])|sort %}
  6. {%- set tags = node_config.get ('tags', [])|sort %}
  7. {%- set address = salt['ffho_net.get_primary_ip'] (node_config, 'v4').ip %}
  8. {%- set address6 = salt['ffho_net.get_primary_ip'] (node_config, 'v6').ip %}
  9. {%- set monitoring_config = node_config.get ('monitoring', {}) %}
  10. {%- set location = node_config.get ('location', {}) %}
  11. {%- set status = node_config.get ('status', 'active') %}
  12. {%- if 'icinga2server' not in roles and node_config.get('platform') == 'linux' %}
  13. object Endpoint "{{ node_id }}" {
  14. host = "{{ node_id }}"
  15. }
  16. object Zone "{{ node_id }}" {
  17. endpoints = [ "{{ node_id }}" ]
  18. parent = "master"
  19. }
  20. {%- endif %}
  21. object Host "{{ node_id }}" {
  22. import "generic-host"
  23. display_name = "{{ node_id }}"
  24. address = "{{ address }}"
  25. address6 = "{{ address6 }}"
  26. {%- if status != 'active' %}
  27. # This node has status {{ status }}, don't whine about anything here
  28. enable_notifications = false
  29. {%- endif %}
  30. vars.os = "{{ node_config.get('platform') or "" }}"
  31. vars.role = "{{ node_config.get('role', '') }}"
  32. vars.roles = [
  33. {%- for role in roles %}
  34. "{{ role }}",
  35. {%- endfor %}
  36. ]
  37. vars.sites = [
  38. {%- for site in sites %}
  39. "{{ site }}",
  40. {%- endfor %}
  41. ]
  42. vars.tags = [
  43. {%- for tag in tags %}
  44. "{{ tag }}",
  45. {%- endfor %}
  46. ]
  47. {#- Bare-metal host #}
  48. {%- if node_config.get ('hardware', False) %}
  49. # Bare metal host
  50. vars.hardware = true
  51. vars.manufacturer = "{{ node_config['manufacturer']|replace ('"', '\"') }}"
  52. vars.model = "{{ node_config['model']|replace ('"', '\\"') }}"
  53. {%- endif %}
  54. {#- VM #}
  55. {%- if node_config.get ('virtual', False) %}
  56. # VM
  57. vars.virtual = true
  58. vars.vm = {
  59. "vcpus" = {{ node_config['vm_config']['vcpus'] }},
  60. "memory" = {{ node_config['vm_config']['memory'] }},
  61. "disk" = {{ node_config['vm_config']['disk'] }},
  62. }
  63. {%- endif %}
  64. {#- Location #}
  65. {%- if location %}
  66. # Location
  67. vars.location = {
  68. {%- if "region" in location %}
  69. "region" = {
  70. "code" = "{{ location['region'].get("code") }}",
  71. "name" = "{{ location['region'].get("name") }}",
  72. },
  73. {%- endif %}
  74. {%- if "site" in location %}
  75. "site" = {
  76. "code" = "{{ location['site'].get("code") }}",
  77. "desc" = "{{ location['site'].get("desc") }}",
  78. }
  79. {%- endif %}
  80. }
  81. {%- endif %}
  82. {#- Special monitoring related config for this host? #}
  83. {%- if 'host_vars' in monitoring_config %}
  84. # Host vars for node
  85. {%- for key, value in monitoring_config.get ('host_vars').items ()|sort %}
  86. vars.{{ key }} = "{{ value }}"
  87. {%- endfor %}
  88. {%- endif %}
  89. {%- if 'service_param' in monitoring_config %}
  90. # Service params
  91. vars.service_param = {
  92. {%- for service, params in monitoring_config.get ('service_param').items ()|sort %}
  93. "{{ service }}" = {
  94. {%- for entry, value in params.items ()|sort %}
  95. {%- if value is boolean %}
  96. "{{ entry }}" = {{ value|lower }},
  97. {%- else %}
  98. "{{ entry }}" = "{{ value }}",
  99. {%- endif %}
  100. {%- endfor %}
  101. },
  102. {%- endfor %}
  103. }
  104. {%- endif %}
  105. }