host.conf.tmpl 2.6 KB

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