init.sls 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #
  2. # Anycast Healthchecker
  3. #
  4. {% set node_roles = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
  5. {% set config = salt['pillar.get']('anycast-healtchecker', {}) %}
  6. include:
  7. - bird
  8. # Install the package and enable/start the service
  9. anycast-healthchecker:
  10. pkg.installed:
  11. - name: anycast-healthchecker
  12. service.running:
  13. - enable: True
  14. - restart: True
  15. - require:
  16. - file: /etc/anycast-healthchecker/anycast-healthchecker.conf
  17. - file: Cleanup /etc/anycast-healthchecker/check.d
  18. # Main configuration
  19. /etc/anycast-healthchecker/anycast-healthchecker.conf:
  20. file.managed:
  21. - source: salt://anycast-healthchecker/anycast-healthchecker.conf
  22. - template: jinja
  23. - watch_in:
  24. - service: anycast-healthchecker
  25. # Clean up any previosly configured checks for roles not present anymore
  26. Cleanup /etc/anycast-healthchecker/check.d:
  27. file.directory:
  28. - name: /etc/anycast-healthchecker/check.d
  29. - clean: true
  30. # Configure service checks for any role configured for this node
  31. {%- for srv_by_role, srv_cfg in salt['pillar.get']('anycast-healtchecker:services', {}).items()|sort %}
  32. {% if srv_by_role not in node_roles %}
  33. {% continue %}
  34. {% endif %}
  35. /etc/anycast-healthchecker/check.d/{{ srv_by_role }}.conf:
  36. file.managed:
  37. - source: salt://anycast-healthchecker/check.conf.tmpl
  38. - template: jinja
  39. - context:
  40. service: {{ srv_by_role }}
  41. service_config: {{ srv_cfg }}
  42. - watch_in:
  43. - service: anycast-healthchecker
  44. - require_in:
  45. - file: Cleanup /etc/anycast-healthchecker/check.d
  46. {%- endfor %}
  47. # Create file /var/lib/anycast-healthchecker/anycast-prefixes-v4.conf is not present
  48. /var/lib/anycast-healthchecker/anycast-prefixes-v4.conf:
  49. file.managed:
  50. - user: bird
  51. - replace: False # Don't touch file contents when file already is present!
  52. - contents: 'define ANYCAST_ADVERTISE = [{{ config['dummy_ip_prefixes'][4] }}];'
  53. - require:
  54. - pkg: anycast-healthchecker
  55. /var/lib/anycast-healthchecker/anycast-prefixes-v6.conf:
  56. file.managed:
  57. - user: bird
  58. - replace: False # Don't touch file contents when file already is present!
  59. - contents: 'define ANYCAST_ADVERTISE = [{{ config['dummy_ip_prefixes'][6] }}];'
  60. - require:
  61. - pkg: anycast-healthchecker
  62. # Install bird direct protocol for anycast_srv interface
  63. /etc/bird/bird.d/anycast-service.conf:
  64. file.managed:
  65. - source: salt://anycast-healthchecker/bird.anycast-service.conf
  66. - template: jinja
  67. proto: v4
  68. - require:
  69. - pkg: anycast-healthchecker
  70. - file: /var/lib/anycast-healthchecker/anycast-prefixes-v4.conf
  71. - watch_in:
  72. - cmd: bird-configure
  73. /etc/bird/bird6.d/anycast-service.conf:
  74. file.managed:
  75. - source: salt://anycast-healthchecker/bird.anycast-service.conf
  76. - template: jinja
  77. proto: v6
  78. - require:
  79. - pkg: anycast-healthchecker
  80. - file: /var/lib/anycast-healthchecker/anycast-prefixes-v6.conf
  81. - watch_in:
  82. - cmd: bird6-configure