init.sls 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. nginx:
  7. pkg.installed:
  8. - name: {{nginx_pkg}}
  9. {% if grains.oscodename in ['jessie'] %}
  10. - fromrepo: {{ grains.oscodename }}-backports
  11. {% endif %}
  12. service.running:
  13. - enable: TRUE
  14. - reload: TRUE
  15. - require:
  16. - pkg: nginx
  17. - watch:
  18. - cmd: nginx-configtest
  19. # Add cache directory
  20. nginx-cache:
  21. file.directory:
  22. - name: /srv/cache
  23. - user: www-data
  24. - group: www-data
  25. - require:
  26. - pkg: nginx
  27. - require_in:
  28. - cmd: nginx-configtest
  29. # Install meaningful main configuration (SSL tweaks 'n stuff)
  30. /etc/nginx/nginx.conf:
  31. file.managed:
  32. - source: salt://nginx/nginx.conf
  33. - template: jinja
  34. - watch_in:
  35. - cmd: nginx-configtest
  36. # Disable default configuration
  37. /etc/nginx/sites-enabled/default:
  38. file.absent:
  39. - watch_in:
  40. - cmd: nginx-configtest
  41. # Install website configuration files configured for this node
  42. {% for website, website_config in node_config.get('nginx', {}).get('websites', {}).items() %}
  43. /etc/nginx/sites-enabled/{{website}}:
  44. file.managed:
  45. - source: salt://nginx/{{website}}
  46. - template: jinja
  47. config: {{ website_config }}
  48. - require:
  49. - pkg: nginx
  50. - watch_in:
  51. - cmd: nginx-configtest
  52. {% endfor %}
  53. {% if 'frontend' in node_config.get('roles', []) %}
  54. {% for domain, config in pillar.get('frontend', {}).items()|sort %}
  55. {% if 'file' in config %}
  56. /etc/nginx/sites-enabled/{{domain}}:
  57. file.managed:
  58. - source: salt://nginx/{{config.file}}
  59. - template: jinja
  60. - require:
  61. - pkg: nginx
  62. - watch_in:
  63. - cmd: nginx-configtest
  64. {% endif %}
  65. {% endfor %}
  66. /etc/nginx/sites-enabled/ff-frontend.conf:
  67. file.managed:
  68. - source: salt://nginx/ff-frontend.conf
  69. - template: jinja
  70. - require:
  71. - pkg: nginx
  72. - watch_in:
  73. - cmd: nginx-configtest
  74. {% endif %}
  75. # Test configuration before reload
  76. nginx-configtest:
  77. cmd.wait:
  78. - name: /usr/sbin/nginx -t