init.sls 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #
  2. # respondd
  3. #
  4. {% set sites_all = pillar.get ('sites') %}
  5. {% set sites_node = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':sites', []) %}
  6. /srv/ffho-respondd:
  7. file.directory
  8. ffho-respondd:
  9. pkg.installed:
  10. - pkgs:
  11. - git
  12. - lsb-release
  13. - ethtool
  14. - python3
  15. - python3-netifaces
  16. git.latest:
  17. - name: https://git.ffho.net/FreifunkHochstift/ffho-respondd.git
  18. - force_fetch: True
  19. - target: /srv/ffho-respondd
  20. - require:
  21. - file: /srv/ffho-respondd
  22. /etc/systemd/system/respondd@.service:
  23. file.managed:
  24. - source: salt://respondd/respondd@.service
  25. - require:
  26. - git: ffho-respondd
  27. {% set node_config = salt['pillar.get']('nodes:' ~ grains['id'], {}) %}
  28. {% set sites_config = salt['pillar.get']('sites', {}) %}
  29. {% set ifaces = salt['ffho_net.get_interface_config'](node_config, sites_config) %}
  30. {% set device_no = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':id', -1) %}
  31. {% for site in sites_node %}
  32. {% set site_no = salt['pillar.get']('sites:' ~ site ~ ':site_no') %}
  33. {% set mac_address = salt['ffho_net.gen_batman_iface_mac'](site_no, device_no, 'bat') %}
  34. {% set region_code = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':location:region:code', salt['pillar.get']('nodes:' ~ grains['id'] ~ ':site_code', '')) %}
  35. /srv/ffho-respondd/{{site}}.conf:
  36. file.managed:
  37. - source: salt://respondd/respondd-config.tmpl
  38. - template: jinja
  39. - defaults:
  40. bat_iface: "bat-{{site}}"
  41. fastd_peers: "false"
  42. hostname: "{{grains['id'].split('.')[0]}}{% if salt['pillar.get']('nodes:' ~ grains['id'] ~ ':sites', [])|length > 1 or grains.id.startswith('gw') %}-{{site}}{% endif %}"
  43. mcast_iface: {% if 'br-' ~ site in ifaces %}"br-{{site}}"{% else %}"bat-{{site}}"{% endif %}
  44. {% if 'fastd' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) and not 'batman_ext' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
  45. mesh_vpn: [{{ site }}_intergw, {{ site }}_nodes4, {{ site }}_nodes6]
  46. {% else %}
  47. mesh_vpn: False
  48. {% endif %}
  49. site: {{site}}
  50. site_code: "{{ region_code }}"
  51. location: {{salt['pillar.get']('nodes:' ~ grains['id'] ~ ':location', {})}}
  52. - require:
  53. - git: ffho-respondd
  54. {% if grains.id == 'gw05.in.ffho.net' and site == 'pad-cty' %}
  55. Stop respondd@{{site}}:
  56. service.dead:
  57. - name: respondd@{{site}}
  58. - enable: False
  59. {% else %}
  60. respondd@{{site}}:
  61. service.running:
  62. - enable: True
  63. - require:
  64. - file: /srv/ffho-respondd/{{site}}.conf
  65. - file: /etc/systemd/system/respondd@.service
  66. - watch:
  67. - file: /srv/ffho-respondd/{{site}}.conf
  68. - git: ffho-respondd
  69. {% endif %}
  70. {% if 'batman_ext' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
  71. /srv/ffho-respondd/{{site}}-ext.conf:
  72. file.managed:
  73. - source: salt://respondd/respondd-config.tmpl
  74. - template: jinja
  75. - defaults:
  76. bat_iface: "bat-{{site}}-ext"
  77. fastd_peers: "{% if 'fastd_peers' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}true{% else %}false{% endif %}"
  78. hostname: "{{grains['id'].split('.')[0]}}{% if salt['pillar.get']('nodes:' ~ grains['id'] ~ ':sites', [])|length > 1 or grains.id.startswith('gw') %}-{{site}}{% endif %}-ext"
  79. mcast_iface: "bat-{{ site }}-ext"
  80. {% if 'fastd' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
  81. mesh_vpn: [{{ site }}_intergw, {{ site }}_nodes4, {{ site }}_nodes6]
  82. {% else %}
  83. mesh_vpn: False
  84. {% endif %}
  85. site: {{site}}
  86. site_code: "{{salt['pillar.get']('nodes:' ~ grains['id'] ~ ':site_code', '')}}"
  87. location: {{salt['pillar.get']('nodes:' ~ grains['id'] ~ ':location', {})}}
  88. - require:
  89. - git: ffho-respondd
  90. respondd@{{site}}-ext:
  91. service.running:
  92. - enable: True
  93. - require:
  94. - file: /srv/ffho-respondd/{{site}}-ext.conf
  95. - file: /etc/systemd/system/respondd@.service
  96. - watch:
  97. - file: /srv/ffho-respondd/{{site}}-ext.conf
  98. - git: ffho-respondd
  99. {% endif %}
  100. {% endfor %}
  101. #
  102. # Cleanup configurations for previosly configured instances.
  103. {% for site in sites_all if site not in sites_node %}
  104. Cleanup /srv/ffho-respondd/{{site}}.conf:
  105. file.absent:
  106. - name: /srv/ffho-respondd/{{site}}.conf
  107. Cleanup /srv/ffho-respondd/{{site}}-ext.conf:
  108. file.absent:
  109. - name: /srv/ffho-respondd/{{site}}-ext.conf
  110. # stop respondd service
  111. Stop respondd@{{site}}:
  112. service.dead:
  113. - name: respondd@{{site}}
  114. - enable: False
  115. - prereq:
  116. - file: Cleanup /srv/ffho-respondd/{{site}}.conf
  117. Stop respondd@{{site}}-ext:
  118. service.dead:
  119. - name: respondd@{{site}}-ext
  120. - enable: False
  121. - prereq:
  122. - file: Cleanup /srv/ffho-respondd/{{site}}-ext.conf
  123. {% endfor %}