init.sls 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #
  2. # FFHO DNS Server configuration (authoritive / recursive)
  3. #
  4. {% set roles = salt['pillar.get']('node:roles', []) %}
  5. bind9:
  6. pkg.installed:
  7. - name: bind9
  8. service.running:
  9. - enable: True
  10. - reload: True
  11. # Reload command
  12. rndc-reload:
  13. cmd.wait:
  14. - watch: []
  15. - name: /usr/sbin/rndc reload
  16. # Bind options
  17. /etc/bind/named.conf.options:
  18. file.managed:
  19. {% if 'dns-recursor' in roles %}
  20. - source: salt://dns-server/named.conf.options.recursor
  21. {% else %}
  22. - source: salt://dns-server/named.conf.options
  23. {% endif %}
  24. - template: jinja
  25. - require:
  26. - pkg: bind9
  27. - watch_in:
  28. - cmd: rndc-reload
  29. # Configure authoritive zones in local config
  30. /etc/bind/named.conf.local:
  31. file.managed:
  32. - source: salt://dns-server/named.conf.local
  33. - template: jinja
  34. - require:
  35. - pkg: bind9
  36. - watch_in:
  37. - cmd: rndc-reload
  38. # Create zones directory
  39. /etc/bind/zones/:
  40. file.directory:
  41. - makedirs: true
  42. - user: root
  43. - group: root
  44. - mode: 755
  45. - require:
  46. - pkg: bind9
  47. # Copy static zone files
  48. /etc/bind/zones/static:
  49. file.recurse:
  50. - source: salt://dns-server/zones/static/
  51. - file_mode: 644
  52. - dir_mode: 755
  53. - user: root
  54. - group: root
  55. - clean: True
  56. - require:
  57. - file: /etc/bind/zones/
  58. - watch_in:
  59. - cmd: rndc-reload
  60. # Install hybrid zone templates
  61. /etc/bind/zones/hybrid:
  62. file.recurse:
  63. - source: salt://dns-server/zones/hybrid/
  64. - file_mode: 644
  65. - dir_mode: 755
  66. - user: root
  67. - group: root
  68. - clean: True
  69. - require:
  70. - file: /etc/bind/zones/
  71. - watch_in:
  72. - cmd: rndc-reload
  73. # Generate node/interface/PTR entries from NetBox
  74. {% set nodes_config = salt['pillar.get'] ('nodes', {}) %}
  75. {% set sites_config = salt['pillar.get'] ('sites', {}) %}
  76. {% set zones = salt['ffho_dns.generate_DNS_entries'] (nodes_config, sites_config) %}
  77. {% for zone, entries in zones.items () %}
  78. /etc/bind/zones/generated/gen{{ zone }}.zone:
  79. file.managed:
  80. - source: salt://dns-server/zone.gen.tmpl
  81. - template: jinja
  82. - context:
  83. zone: {{ zone }}
  84. entries: {{ entries }}
  85. - require_in:
  86. - file: Clean /etc/bind/zones/generated
  87. - watch_in:
  88. - cmd: rndc-reload
  89. {% endfor %}
  90. Clean /etc/bind/zones/generated:
  91. file.directory:
  92. - name: /etc/bind/zones/generated
  93. - clean: True