init.sls 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #
  2. # Fastd for gateways
  3. #
  4. {% set sites_all = pillar.get ('sites') %}
  5. {% set sites_node = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':sites', {}) %}
  6. {% set device_no = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':id', -1) %}
  7. include:
  8. - network.interfaces
  9. {% if 'fastd_peers' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
  10. - fastd.peers
  11. {% endif %}
  12. fastd-repo:
  13. pkgrepo.managed:
  14. - human_name: Neoraiders fastd repository
  15. - name: deb http://repo.universe-factory.net/debian/ sid main
  16. - dist: sid
  17. - file: /etc/apt/sources.list.d/fastd.list
  18. - keyserver: keyserver.ubuntu.com
  19. - keyid: CB201D9C
  20. # Install fastd (after fastd-repo and the network are configured)
  21. fastd:
  22. pkg.installed:
  23. - name: fastd
  24. - require:
  25. - pkgrepo: fastd-repo
  26. - sls: network.interfaces
  27. /etc/systemd/system/fastd@.service:
  28. file.managed:
  29. - source: salt://fastd/fastd@.service
  30. /etc/fastd:
  31. file.directory:
  32. - user: root
  33. - group: root
  34. - mode: 711
  35. require:
  36. - pkg: fastd
  37. #
  38. # Set up fastd configuration for every network (nodes4, nodes6, intergw-vpn)
  39. # for every site associated for the current minion ID.
  40. #
  41. {% for site in sites_node %}
  42. {% set site_no = salt['pillar.get']('sites:' ~ site ~ ':site_no') %}
  43. {% set networks = ['intergw'] %}
  44. {% if 'fastd_peers' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
  45. {% do networks.extend (['nodes4', 'nodes6']) %}
  46. {% endif %}
  47. {% for network in networks %}
  48. {% set network_type = 'nodes' if network.startswith ('nodes') else network %}
  49. {% set instance_name = site ~ '_' ~ network %}
  50. {% set mac_address = salt['ffho_net.gen_batman_iface_mac'](site_no, device_no, network) %}
  51. /etc/fastd/{{ instance_name }}:
  52. file.directory:
  53. - makedirs: true
  54. - mode: 755
  55. - require:
  56. - file: /etc/fastd
  57. /etc/fastd/{{ instance_name }}/fastd.conf:
  58. file.managed:
  59. - source: salt://fastd/fastd.conf
  60. - template: jinja
  61. network: {{ network }}
  62. network_type: {{ network_type }}
  63. site: {{ site }}
  64. site_no: {{ site_no }}
  65. mac_address: {{ mac_address }}
  66. peer_limit: {{ salt['pillar.get']('nodes:' ~ grains['id'] ~ ':fastd:peer_limit', False) }}
  67. - require:
  68. - file: /etc/fastd/{{ instance_name }}
  69. - watch_in:
  70. /etc/fastd/{{ instance_name }}/secret.conf:
  71. file.managed:
  72. - source: salt://fastd/secret.conf.tmpl
  73. - template: jinja
  74. secret: {{ salt['pillar.get']('nodes:' ~ grains['id'] ~ ':fastd:' ~ network_type + '_privkey') }}
  75. - mode: 600
  76. - user: root
  77. - group: root
  78. - require:
  79. - file: /etc/fastd/{{ instance_name }}
  80. # Create systemd start link
  81. fastd@{{ instance_name }}:
  82. service.running:
  83. - enable: True
  84. - reload: True
  85. - require:
  86. - file: /etc/systemd/system/fastd@.service
  87. - file: /etc/fastd/{{ instance_name }}/fastd.conf
  88. - file: /etc/fastd/{{ instance_name }}/secret.conf
  89. - watch:
  90. - file: /etc/fastd/{{ instance_name }}/fastd.conf
  91. - file: /etc/fastd/{{ instance_name }}/secret.conf
  92. {% endfor %} # // foreach network in $site
  93. #
  94. # Generate Inter-GW peers from pillar
  95. /etc/fastd/{{ site }}_intergw/gateways:
  96. file.directory:
  97. - makedirs: true
  98. - mode: 755
  99. - require:
  100. - file: /etc/fastd/{{ site }}_intergw
  101. #
  102. # Gather all nodes configured for this site
  103. {% set nodes = [] %}
  104. {% for node, node_config in salt['pillar.get']('nodes').items () %}
  105. {% if site in node_config.get ('sites', {}) and 'fastd' in node_config %}
  106. {% do nodes.append (node) %}
  107. {% endif %}
  108. {% endfor %} # // foreach node
  109. # Set up Inter-Gw-VPN link to all nodes of this site
  110. {% for node in nodes|sort %}
  111. /etc/fastd/{{ site }}_intergw/gateways/{{ node }}:
  112. file.managed:
  113. - source: salt://fastd/inter-gw.peer.tmpl
  114. - template: jinja
  115. site: {{ site }}
  116. site_no: {{ site_no }}
  117. node: {{ node }}
  118. pubkey: {{ salt['pillar.get']('nodes:' ~ node ~ ':fastd:intergw_pubkey') }}
  119. - require:
  120. - file: /etc/fastd/{{ site }}_intergw/gateways
  121. {% endfor %} # // foreach site peer
  122. {% endfor %} # // foreach site
  123. #
  124. # Cleanup configurations for previosly configured instances.
  125. # Stop fastd instance before purging the configuration.
  126. {% for site in sites_all if site not in sites_node %}
  127. {% for network in ['intergw', 'nodes4', 'nodes6'] %}
  128. {% set instance_name = site ~ '_' ~ network %}
  129. Cleanup /etc/fastd/{{ instance_name }}:
  130. file.absent:
  131. - name: /etc/fastd/{{ instance_name }}
  132. # Create systemd start link
  133. Stop fastd@{{ instance_name }}:
  134. service.running:
  135. - enable: False
  136. - reload: False
  137. - prereq:
  138. - file: Cleanup /etc/fastd/{{ instance_name }}
  139. {% endfor %}
  140. {% endfor %}
  141. /usr/local/bin/ff_log_vpnpeer:
  142. file.managed:
  143. - source: salt://fastd/ff_log_vpnpeer
  144. - template: jinja
  145. - mode: 755
  146. ff_fastd_con_pkgs:
  147. pkg.installed:
  148. - pkgs:
  149. - socat
  150. - jq
  151. /usr/local/bin/ff_fastd_conn:
  152. file.managed:
  153. - source: salt://fastd/ff_fastd_con
  154. - mode: 755
  155. - user: root
  156. - group: root