init.sls 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #
  2. # respondd
  3. #
  4. {% set sites_all = pillar.get ('sites') %}
  5. {% set sites_node = salt['pillar.get']('node: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']('node', {}) %}
  28. {% set node_roles = node_config.get('roles', []) %}
  29. {% set sites_config = salt['pillar.get']('sites', {}) %}
  30. {% set ifaces = salt['ffho_net.get_interface_config'](node_config, sites_config) %}
  31. {% set device_no = salt['pillar.get']('node:id', -1) %}
  32. {% for site in sites_node %}
  33. {% set site_no = salt['pillar.get']('sites:' ~ site ~ ':site_no') %}
  34. {% set mac_address = salt['ffho_net.gen_batman_iface_mac'](site_no, device_no, 'bat') %}
  35. {% set region_code = salt['pillar.get']('node:location:region:code', salt['pillar.get']('node:site_code', '')) %}
  36. /srv/ffho-respondd/{{site}}.conf:
  37. file.managed:
  38. - source: salt://respondd/respondd-config.tmpl
  39. - template: jinja
  40. - defaults:
  41. bat_iface: "bat-{{site}}"
  42. fastd_peers: "{% if 'fastd_peers' in node_config.get ('roles', []) %}true{% else %}false{% endif %}"
  43. hostname: "{{ grains['id'].split('.')[0] }}{% if node_config.get ('sites', [])|length > 1 or grains.id.startswith('gw') %}-{{site}}{% endif %}"
  44. mcast_iface: {% if 'br-' ~ site in ifaces %}"br-{{site}}"{% else %}"bat-{{site}}"{% endif %}
  45. {% if 'fastd' in node_roles %}
  46. mesh_vpn: [{{ site }}_intergw, {{ site }}_nodes4, {{ site }}_nodes6]
  47. {% else %}
  48. mesh_vpn: False
  49. {% endif %}
  50. site: {{ site }}
  51. site_code: "{{ region_code }}"
  52. location: {{ node_config.get('location', {}) }}
  53. location_hidden: {{ 'location-hidden' in node_config.get ('tags', []) }}
  54. - require:
  55. - git: ffho-respondd
  56. respondd@{{site}}:
  57. service.running:
  58. - enable: True
  59. - require:
  60. - file: /srv/ffho-respondd/{{site}}.conf
  61. - file: /etc/systemd/system/respondd@.service
  62. - watch:
  63. - file: /srv/ffho-respondd/{{site}}.conf
  64. - git: ffho-respondd
  65. {% if 'batman_ext' in node_roles %}
  66. /srv/ffho-respondd/{{site}}-ext.conf:
  67. file.managed:
  68. - source: salt://respondd/respondd-config.tmpl
  69. - template: jinja
  70. - defaults:
  71. bat_iface: "bat-{{site}}-ext"
  72. fastd_peers: "{% if 'fastd_peers' in node_config.get ('roles', []) %}true{% else %}false{% endif %}"
  73. hostname: "{{ grains['id'].split('.')[0] }}{% if node_config.get ('sites', [])|length > 1 or grains.id.startswith('gw') %}-{{site}}{% endif %}-ext"
  74. mcast_iface: "bat-{{ site }}-ext"
  75. {% if 'fastd' in node_roles %}
  76. mesh_vpn: [{{ site }}_intergw, {{ site }}_nodes4, {{ site }}_nodes6]
  77. {% else %}
  78. mesh_vpn: False
  79. {% endif %}
  80. site: {{site}}
  81. site_code: "{{ node_config.get ('site_code', '') }}"
  82. location: {{ node_config.get ('location', {}) }}
  83. - require:
  84. - git: ffho-respondd
  85. respondd@{{site}}-ext:
  86. service.running:
  87. - enable: True
  88. - require:
  89. - file: /srv/ffho-respondd/{{site}}-ext.conf
  90. - file: /etc/systemd/system/respondd@.service
  91. - watch:
  92. - file: /srv/ffho-respondd/{{site}}-ext.conf
  93. - git: ffho-respondd
  94. {% else %}
  95. /srv/ffho-respondd/{{ site }}-ext.conf:
  96. file.absent
  97. respondd@{{ site }}-ext:
  98. service.dead:
  99. - enable: False
  100. - prereq:
  101. - file: /srv/ffho-respondd/{{ site }}-ext.conf
  102. {% endif %}
  103. {% endfor %}
  104. #
  105. # Cleanup configurations for previosly configured instances.
  106. {% for site in sites_all if site not in sites_node %}
  107. Cleanup /srv/ffho-respondd/{{site}}.conf:
  108. file.absent:
  109. - name: /srv/ffho-respondd/{{site}}.conf
  110. Cleanup /srv/ffho-respondd/{{site}}-ext.conf:
  111. file.absent:
  112. - name: /srv/ffho-respondd/{{site}}-ext.conf
  113. # stop respondd service
  114. Stop respondd@{{site}}:
  115. service.dead:
  116. - name: respondd@{{site}}
  117. - enable: False
  118. - prereq:
  119. - file: Cleanup /srv/ffho-respondd/{{site}}.conf
  120. Stop respondd@{{site}}-ext:
  121. service.dead:
  122. - name: respondd@{{site}}-ext
  123. - enable: False
  124. - prereq:
  125. - file: Cleanup /srv/ffho-respondd/{{site}}-ext.conf
  126. {% endfor %}