host.conf.tmpl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 %}
  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 = "Linux"
  31. vars.roles = [
  32. {%- for role in roles %}
  33. "{{ role }}",
  34. {%- endfor %}
  35. ]
  36. vars.sites = [
  37. {%- for site in sites %}
  38. "{{ site }}",
  39. {%- endfor %}
  40. ]
  41. vars.tags = [
  42. {%- for tag in tags %}
  43. "{{ tag }}",
  44. {%- endfor %}
  45. ]
  46. {#- Bare-metal host #}
  47. {%- if node_config.get ('hardware', False) %}
  48. # Bare metal host
  49. vars.hardware = true
  50. vars.manufacturer = "{{ node_config['manufacturer']|replace ('"', '\"') }}"
  51. vars.model = "{{ node_config['model']|replace ('"', '\\"') }}"
  52. {%- endif %}
  53. {#- VM #}
  54. {%- if node_config.get ('virtual', False) %}
  55. # VM
  56. vars.virtual = true
  57. vars.vm = {
  58. "vcpus" = {{ node_config['vm_config']['vcpus'] }},
  59. "memory" = {{ node_config['vm_config']['memory'] }},
  60. "disk" = {{ node_config['vm_config']['disk'] }},
  61. }
  62. {%- endif %}
  63. {#- Location #}
  64. {%- if location %}
  65. # Location
  66. vars.location = {
  67. {%- if "region" in location %}
  68. "region" = {
  69. "code" = "{{ location['region'].get("code") }}",
  70. "name" = "{{ location['region'].get("name") }}",
  71. },
  72. {%- endif %}
  73. {%- if "site" in location %}
  74. "site" = {
  75. "code" = "{{ location['site'].get("code") }}",
  76. "desc" = "{{ location['site'].get("desc") }}",
  77. }
  78. {%- endif %}
  79. }
  80. {%- endif %}
  81. {#- Special monitoring related config for this host? #}
  82. {%- if 'host_vars' in monitoring_config %}
  83. # Host vars for node
  84. {%- for key, value in monitoring_config.get ('host_vars').items ()|sort %}
  85. vars.{{ key }} = "{{ value }}"
  86. {%- endfor %}
  87. {%- endif %}
  88. {%- if 'service_param' in monitoring_config %}
  89. # Service params
  90. vars.service_param = {
  91. {%- for service, params in monitoring_config.get ('service_param').items ()|sort %}
  92. "{{ service }}" = {
  93. {%- for entry, value in params.items ()|sort %}
  94. "{{ entry }}" = "{{ value }}",
  95. {%- endfor %}
  96. },
  97. {%- endfor %}
  98. }
  99. {%- endif %}
  100. }