init.sls 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #
  2. # Nginx
  3. #
  4. {% set nginx_pkg = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':nginx:pkg', 'nginx') %}
  5. nginx:
  6. pkg.installed:
  7. - name: {{nginx_pkg}}
  8. {% if grains['oscodename'] == 'jessie' %}
  9. - fromrepo: jessie-backports
  10. {% endif %}
  11. service.running:
  12. - enable: TRUE
  13. - reload: TRUE
  14. - require:
  15. - pkg: nginx
  16. - file: nginx-cache
  17. - watch:
  18. - cmd: nginx-configtest
  19. # generate custom DH parameters
  20. {% if grains['saltversion'] >= '2014.7.0' %}
  21. nginx-dhparam:
  22. cmd.run:
  23. - name: openssl dhparam -out /etc/ssl/dhparam.pem 4096
  24. - creates: /etc/ssl/dhparam.pem
  25. - require_in:
  26. - serivce: nginx
  27. {% endif %}
  28. # Add cache directory
  29. nginx-cache:
  30. file.directory:
  31. - name: /srv/cache
  32. - user: www-data
  33. - group: www-data
  34. # Install meaningful main configuration (SSL tweaks 'n stuff)
  35. /etc/nginx/nginx.conf:
  36. file.managed:
  37. - source: salt://nginx/nginx.conf
  38. - template: jinja
  39. - watch_in:
  40. - cmd: nginx-configtest
  41. # Disable default configuration
  42. /etc/nginx/sites-enabled/default:
  43. file.absent:
  44. - watch_in:
  45. - cmd: nginx-configtest
  46. # Install website configuration files configured for this node
  47. {% for website in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':nginx:websites', []) %}
  48. /etc/nginx/sites-enabled/{{website}}:
  49. file.managed:
  50. - source: salt://nginx/{{website}}
  51. - template: jinja
  52. - require:
  53. - pkg: nginx
  54. - watch_in:
  55. - cmd: nginx-configtest
  56. {% endfor %}
  57. # Test configuration before reload
  58. nginx-configtest:
  59. cmd.wait:
  60. - name: /usr/sbin/nginx -t