init.sls 2.2 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. 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. /etc/nginx/ffho.d:
  37. file.recurse:
  38. - source: salt://nginx/ffho.d
  39. - file_mode: 755
  40. - dir_mode: 755
  41. - user: root
  42. - group: root
  43. - clean: True
  44. - watch_in:
  45. - cmd: nginx-configtest
  46. # Disable default configuration
  47. /etc/nginx/sites-enabled/default:
  48. file.absent:
  49. - watch_in:
  50. - cmd: nginx-configtest
  51. # Install website configuration files configured for this node
  52. {% for website, website_config in node_config.get('nginx', {}).get('websites', {}).items() %}
  53. /etc/nginx/sites-enabled/{{website}}:
  54. file.managed:
  55. - source: salt://nginx/{{website}}
  56. - template: jinja
  57. config: {{ website_config }}
  58. - require:
  59. - pkg: nginx
  60. - watch_in:
  61. - cmd: nginx-configtest
  62. {% endfor %}
  63. {% if 'frontend' in node_config.get('roles', []) %}
  64. {% for domain, config in pillar.get('frontend', {}).items()|sort %}
  65. {% if 'file' in config %}
  66. /etc/nginx/sites-enabled/{{domain}}:
  67. file.managed:
  68. - source: salt://nginx/{{config.file}}
  69. - template: jinja
  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