init.sls 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #
  2. # Nginx
  3. #
  4. {% set node_config = salt['pillar.get']('nodes:' ~ grains.id) %}
  5. {% set nginx_pkg = node_config.get('nginx:pkg', 'nginx') %}
  6. {% set acme_thumbprint = salt['pillar.get']('acme:thumbprint') %}
  7. nginx:
  8. pkg.installed:
  9. - name: {{nginx_pkg}}
  10. service.running:
  11. - enable: TRUE
  12. - reload: TRUE
  13. - require:
  14. - pkg: nginx
  15. - watch:
  16. - cmd: nginx-configtest
  17. # Add cache directory
  18. nginx-cache:
  19. file.directory:
  20. - name: /srv/cache
  21. - user: www-data
  22. - group: www-data
  23. - require:
  24. - pkg: nginx
  25. - require_in:
  26. - cmd: nginx-configtest
  27. # Install meaningful main configuration (SSL tweaks 'n stuff)
  28. /etc/nginx/nginx.conf:
  29. file.managed:
  30. - source: salt://nginx/nginx.conf
  31. - template: jinja
  32. - watch_in:
  33. - cmd: nginx-configtest
  34. /etc/nginx/ffho.d:
  35. file.recurse:
  36. - source: salt://nginx/ffho.d
  37. - file_mode: 755
  38. - dir_mode: 755
  39. - user: root
  40. - group: root
  41. - clean: True
  42. - watch_in:
  43. - cmd: nginx-configtest
  44. # Disable default configuration
  45. /etc/nginx/sites-enabled/default:
  46. file.absent:
  47. - watch_in:
  48. - cmd: nginx-configtest
  49. # Install website configuration files configured for this node
  50. {% for website, website_config in node_config.get('nginx', {}).get('websites', {}).items() %}
  51. /etc/nginx/sites-enabled/{{website}}:
  52. file.managed:
  53. - source: salt://nginx/{{website}}
  54. - template: jinja
  55. config: {{ website_config }}
  56. acme_thumbprint: {{ acme_thumbprint }}
  57. - require:
  58. - pkg: nginx
  59. - watch_in:
  60. - cmd: nginx-configtest
  61. {% endfor %}
  62. {% if 'frontend' in node_config.get('roles', []) %}
  63. {% for domain, config in pillar.get('frontend', {}).items()|sort %}
  64. {% if 'file' in config %}
  65. /etc/nginx/sites-enabled/{{domain}}:
  66. file.managed:
  67. - source: salt://nginx/{{config.file}}
  68. - template: jinja
  69. acme_thumbprint: {{ acme_thumbprint }}
  70. - require:
  71. - pkg: nginx
  72. - watch_in:
  73. - cmd: nginx-configtest
  74. {% endif %}
  75. {% endfor %}
  76. /etc/nginx/sites-enabled/ff-frontend.conf:
  77. file.managed:
  78. - source: salt://nginx/ff-frontend.conf
  79. - template: jinja
  80. - require:
  81. - pkg: nginx
  82. - watch_in:
  83. - cmd: nginx-configtest
  84. {% endif %}
  85. # Test configuration before reload
  86. nginx-configtest:
  87. cmd.wait:
  88. - name: /usr/sbin/nginx -t