init.sls 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. - target: /srv/ffho-respondd
  19. - require:
  20. - file: /srv/ffho-respondd
  21. /etc/systemd/system/respondd@.service:
  22. file.managed:
  23. - source: salt://respondd/respondd@.service
  24. - require:
  25. - git: ffho-respondd
  26. {% set node_config = salt['pillar.get']('nodes:' ~ grains['id'], {}) %}
  27. {% set sites_config = salt['pillar.get']('sites', {}) %}
  28. {% set ifaces = salt['ffho_net.get_interface_config'](node_config, sites_config) %}
  29. {% set device_no = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':id', -1) %}
  30. {% for site in sites_node %}
  31. {% set site_no = salt['pillar.get']('sites:' ~ site ~ ':site_no') %}
  32. {% set mac_address = salt['ffho_net.gen_batman_iface_mac'](site_no, device_no, 'dummy') %}
  33. /srv/ffho-respondd/{{site}}.conf:
  34. file.managed:
  35. - source: salt://respondd/respondd-config.tmpl
  36. - template: jinja
  37. - defaults:
  38. mac_address: {{ mac_address }}
  39. {% if 'batman_ext' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
  40. bat_iface: "bat-{{site}}-ext"
  41. {% else %}
  42. bat_iface: "bat-{{site}}"
  43. {% endif %}
  44. {% if 'fastd_peers' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
  45. fastd_peers: "true"
  46. {% else %}
  47. fastd_peers: "false"
  48. {% endif %}
  49. {% if salt['pillar.get']('nodes:' ~ grains['id'] ~ ':sites', [])|length > 1 %}
  50. hostname: "{{grains['id'].split('.')[0]}}-{{site}}"
  51. {% else %}
  52. hostname: "{{grains['id'].split('.')[0]}}"
  53. {% endif %}
  54. {% if 'br-' ~ site in ifaces %}
  55. mcast_iface: "br-{{site}}"
  56. {% else %}
  57. mcast_iface: "bat-{{site}}"
  58. {% endif %}
  59. {% if 'fastd' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
  60. mesh_vpn: [{{ site }}_intergw, {{ site }}_nodes4, {{ site }}_nodes6]
  61. {% else %}
  62. mesh_vpn: False
  63. {% endif %}
  64. site: {{site}}
  65. site_code: "{{salt['pillar.get']('nodes:' ~ grains['id'] ~ ':site_code', '')}}"
  66. location: {{salt['pillar.get']('nodes:' ~ grains['id'] ~ ':location', {})}}
  67. - require:
  68. - git: ffho-respondd
  69. respondd@{{site}}:
  70. service.running:
  71. - enable: True
  72. - require:
  73. - file: /srv/ffho-respondd/{{site}}.conf
  74. - file: /etc/systemd/system/respondd@.service
  75. - watch:
  76. - file: /srv/ffho-respondd/{{site}}.conf
  77. - git: ffho-respondd
  78. {% endfor %}
  79. #
  80. # Cleanup configurations for previosly configured instances.
  81. {% for site in sites_all if site not in sites_node %}
  82. Cleanup /srv/ffho-respondd/{{site}}.conf:
  83. file.absent:
  84. - name: /srv/ffho-respondd/{{site}}.conf
  85. # stop respondd service
  86. Stop respondd@{{site}}:
  87. service.dead:
  88. - name: respondd@{{site}}
  89. - enable: False
  90. - prereq:
  91. - file: Cleanup /srv/ffho-respondd/{{site}}.conf
  92. {% endfor %}