init.sls 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 in ['jessie'] %}
  9. - fromrepo: {{ grains.oscodename }}-backports
  10. {% endif %}
  11. service.running:
  12. - enable: TRUE
  13. - reload: TRUE
  14. - require:
  15. - pkg: nginx
  16. - watch:
  17. - cmd: nginx-configtest
  18. # generate custom DH parameters
  19. {% if grains['saltversion'] >= '2014.7.0' %}
  20. nginx-dhparam:
  21. cmd.run:
  22. - name: openssl dhparam -out /etc/ssl/dhparam.pem 4096
  23. - creates: /etc/ssl/dhparam.pem
  24. - require_in:
  25. - serivce: nginx
  26. {% endif %}
  27. # Add cache directory
  28. nginx-cache:
  29. file.directory:
  30. - name: /srv/cache
  31. - user: www-data
  32. - group: www-data
  33. - require:
  34. - pkg: nginx
  35. - require_in:
  36. - cmd: nginx-configtest
  37. # Install meaningful main configuration (SSL tweaks 'n stuff)
  38. /etc/nginx/nginx.conf:
  39. file.managed:
  40. - source: salt://nginx/nginx.conf
  41. - template: jinja
  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 in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':nginx:websites', []) %}
  51. /etc/nginx/sites-enabled/{{website}}:
  52. file.managed:
  53. - source: salt://nginx/{{website}}
  54. - template: jinja
  55. - require:
  56. - pkg: nginx
  57. - watch_in:
  58. - cmd: nginx-configtest
  59. {% endfor %}
  60. {% if 'frontend' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
  61. {% for domain, config in pillar.get('frontend', {}).items()|sort %}
  62. {% if 'file' in config %}
  63. /etc/nginx/sites-enabled/{{domain}}:
  64. file.managed:
  65. - source: salt://nginx/{{config.file}}
  66. - template: jinja
  67. - require:
  68. - pkg: nginx
  69. - watch_in:
  70. - cmd: nginx-configtest
  71. {% endif %}
  72. {% endfor %}
  73. /etc/nginx/sites-enabled/ff-frontend.conf:
  74. file.managed:
  75. - source: salt://nginx/ff-frontend.conf
  76. - template: jinja
  77. - require:
  78. - pkg: nginx
  79. - watch_in:
  80. - cmd: nginx-configtest
  81. {% endif %}
  82. # Test configuration before reload
  83. nginx-configtest:
  84. cmd.wait:
  85. - name: /usr/sbin/nginx -t