init.sls 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #
  2. # Fastd for gateways
  3. #
  4. {% set sites_all = pillar.get ('sites') %}
  5. {% set node_config = salt['pillar.get']('nodes:' ~ grains.id, {}) %}
  6. {% set sites_node = node_config.get('sites', {}) %}
  7. {% set device_no = node_config.get('id', -1) %}
  8. # Install fastd
  9. fastd:
  10. pkg.installed:
  11. - name: fastd
  12. service.dead:
  13. - enable: False
  14. /etc/systemd/system/fastd@.service:
  15. file.managed:
  16. - source: salt://fastd/fastd@.service
  17. /etc/fastd:
  18. file.directory:
  19. - user: root
  20. - group: root
  21. - mode: 711
  22. require:
  23. - pkg: fastd
  24. #
  25. # Is this instance to be used by external clients?
  26. {% if 'fastd_peers' in node_config.get ('roles', []) %}
  27. # publish blacklist
  28. /etc/fastd/peers-blacklist:
  29. file.managed:
  30. - source: salt://fastd/peers-blacklist
  31. - user: root
  32. - group: root
  33. - mode: 644
  34. - require:
  35. - file: /etc/fastd
  36. /etc/fastd/verify-peer.sh:
  37. file.managed:
  38. - source: salt://fastd/verify-peer.sh
  39. - user: root
  40. - group: root
  41. - mode: 744
  42. - require:
  43. - file: /etc/fastd
  44. {% endif %}
  45. #
  46. # Set up fastd configuration for every network (nodes4, nodes6, intergw-vpn)
  47. # for every site associated for the current minion ID.
  48. #
  49. {% for site in sites_all %}
  50. {% set networks_absent = [] %}
  51. {% set networks_present = [] %}
  52. {% set site_no = sites_all.get(site, {}).get('site_no') %}
  53. {% if site in sites_node %}
  54. {% do networks_present.extend(['intergw']) %}
  55. {% if 'fastd_peers' in node_config.get('roles', []) %}
  56. {% do networks_present.extend(['nodes4', 'nodes6']) %}
  57. {% else %}
  58. {% do networks_absent.extend(['nodes4', 'nodes6']) %}
  59. {% endif %}
  60. {% else %}
  61. {% do networks_absent.extend(['intergw', 'nodes4', 'nodes6']) %}
  62. {% endif %}
  63. {% for network in networks_present %}
  64. {% set network_type = 'nodes' if network.startswith ('nodes') else network %}
  65. {% set instance_name = site ~ '_' ~ network %}
  66. {% set mac_address = salt['ffho_net.gen_batman_iface_mac'](site_no, device_no, network) %}
  67. /etc/fastd/{{ instance_name }}:
  68. file.directory:
  69. - makedirs: true
  70. - mode: 755
  71. - require:
  72. - file: /etc/fastd
  73. /etc/fastd/{{ instance_name }}/fastd.conf:
  74. file.managed:
  75. - source: salt://fastd/fastd.conf
  76. - template: jinja
  77. network: {{ network }}
  78. network_type: {{ network_type }}
  79. secret: {{ node_config.get('fastd', {}).get(network_type ~ '_privkey') }}
  80. site: {{ site }}
  81. site_no: {{ site_no }}
  82. mac_address: {{ mac_address }}
  83. {% if 'batman_ext' in node_config.get('roles', []) %}
  84. bat_iface: bat-{{ site }}-ext
  85. {% else %}
  86. bat_iface: bat-{{ site }}
  87. {% endif %}
  88. peer_limit: {{ node_config.get('fastd', {}).get('peer_limit', False) }}
  89. - require:
  90. - file: /etc/fastd/{{ instance_name }}
  91. /etc/fastd/{{ instance_name }}/secret.conf:
  92. file.absent
  93. # Create systemd start link
  94. fastd@{{ instance_name }}:
  95. service.running:
  96. - enable: True
  97. - require:
  98. - file: /etc/systemd/system/fastd@.service
  99. - file: /etc/fastd/{{ instance_name }}/fastd.conf
  100. - service: fastd
  101. - watch:
  102. - file: /etc/fastd/{{ instance_name }}/fastd.conf
  103. {% endfor %}{# for network in networks #}
  104. #
  105. # Cleanup configurations for previosly configured instances.
  106. # Stop fastd instance before purging the configuration.
  107. {% for network in networks_absent %}
  108. {% set instance_name = site ~ '_' ~ network %}
  109. Cleanup /etc/fastd/{{ instance_name }}:
  110. file.absent:
  111. - name: /etc/fastd/{{ instance_name }}
  112. # stop fastd service
  113. Stop fastd@{{ instance_name }}:
  114. service.dead:
  115. - name: fastd@{{ instance_name }}
  116. - enable: False
  117. - prereq:
  118. - file: Cleanup /etc/fastd/{{ instance_name }}
  119. {% endfor %}
  120. {% endfor %}{# for site in sites_all #}
  121. ff_fastd_con_pkgs:
  122. pkg.installed:
  123. - pkgs:
  124. - socat
  125. - jq
  126. /usr/local/bin/ff_fastd_conn:
  127. file.managed:
  128. - source: salt://fastd/ff_fastd_conn
  129. - mode: 755
  130. - user: root
  131. - group: root