init.sls 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 node_config.get ('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 node_config.get ('roles', []) and not 'batman_ext' in node_config.get ('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: {{ node_config.get('location', {}) }}
  52. location_hidden: {{ 'location-hidden' in node_config.get ('tags', []) }}
  53. - require:
  54. - git: ffho-respondd
  55. respondd@{{site}}:
  56. service.running:
  57. - enable: True
  58. - require:
  59. - file: /srv/ffho-respondd/{{site}}.conf
  60. - file: /etc/systemd/system/respondd@.service
  61. - watch:
  62. - file: /srv/ffho-respondd/{{site}}.conf
  63. - git: ffho-respondd
  64. {% if 'batman_ext' in node_config.get('roles', []) %}
  65. /srv/ffho-respondd/{{site}}-ext.conf:
  66. file.managed:
  67. - source: salt://respondd/respondd-config.tmpl
  68. - template: jinja
  69. - defaults:
  70. bat_iface: "bat-{{site}}-ext"
  71. fastd_peers: "{% if 'fastd_peers' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}true{% else %}false{% endif %}"
  72. hostname: "{{ grains['id'].split('.')[0] }}{% if node_config.get ('sites', [])|length > 1 or grains.id.startswith('gw') %}-{{site}}{% endif %}-ext"
  73. mcast_iface: "bat-{{ site }}-ext"
  74. {% if 'fastd' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
  75. mesh_vpn: [{{ site }}_intergw, {{ site }}_nodes4, {{ site }}_nodes6]
  76. {% else %}
  77. mesh_vpn: False
  78. {% endif %}
  79. site: {{site}}
  80. site_code: "{{ node_config.get ('site_code', '') }}"
  81. location: {{ node_config.get ('location', {}) }}
  82. - require:
  83. - git: ffho-respondd
  84. respondd@{{site}}-ext:
  85. service.running:
  86. - enable: True
  87. - require:
  88. - file: /srv/ffho-respondd/{{site}}-ext.conf
  89. - file: /etc/systemd/system/respondd@.service
  90. - watch:
  91. - file: /srv/ffho-respondd/{{site}}-ext.conf
  92. - git: ffho-respondd
  93. {% endif %}
  94. {% endfor %}
  95. #
  96. # Cleanup configurations for previosly configured instances.
  97. {% for site in sites_all if site not in sites_node %}
  98. Cleanup /srv/ffho-respondd/{{site}}.conf:
  99. file.absent:
  100. - name: /srv/ffho-respondd/{{site}}.conf
  101. Cleanup /srv/ffho-respondd/{{site}}-ext.conf:
  102. file.absent:
  103. - name: /srv/ffho-respondd/{{site}}-ext.conf
  104. # stop respondd service
  105. Stop respondd@{{site}}:
  106. service.dead:
  107. - name: respondd@{{site}}
  108. - enable: False
  109. - prereq:
  110. - file: Cleanup /srv/ffho-respondd/{{site}}.conf
  111. Stop respondd@{{site}}-ext:
  112. service.dead:
  113. - name: respondd@{{site}}-ext
  114. - enable: False
  115. - prereq:
  116. - file: Cleanup /srv/ffho-respondd/{{site}}-ext.conf
  117. {% endfor %}