init.sls 4.7 KB

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