init.sls 2.4 KB

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