Playbooks to a new Lilik
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
3.8 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. ---
  2. - include: service.yaml
  3. # static: yes # see static include issue: https://github.com/ansible/ansible/issues/13485
  4. vars:
  5. service_name: nginx
  6. service_packages:
  7. - nginx
  8. - name: install letsencrypt dependencies
  9. apt:
  10. name: "{{ item }}"
  11. state: present
  12. update_cache: yes
  13. cache_valid_time: 3600
  14. with_items: "{{ letsencrypt_requirements }}"
  15. when: letsencrypt|bool
  16. - name: provision directories for site specific configurations
  17. file:
  18. path: /etc/nginx/{{ item }}
  19. state: directory
  20. owner: root
  21. group: root
  22. mode: 0755
  23. with_items:
  24. - "sites-available"
  25. - "sites-enabled"
  26. - name: provision letsencrypt challenge folder
  27. file:
  28. path: "{{ letsencrypt_challenge_webroot }}/.well-known/acme-challenge"
  29. state: directory
  30. owner: root
  31. group: root
  32. mode: 0755
  33. when: letsencrypt|bool
  34. - name: upload nginx configuration
  35. template:
  36. src: nginx.conf.j2
  37. dest: /etc/nginx/nginx.conf
  38. - name: disable nginx default configuration
  39. file:
  40. path: /etc/nginx/sites-enabled/default
  41. state: absent
  42. notify: restart nginx
  43. - name: install php-fpm
  44. apt:
  45. name: "{{ item }}"
  46. state: present
  47. update_cache: yes
  48. cache_valid_time: 3600
  49. with_items:
  50. - php-fpm
  51. when: php | bool
  52. notify:
  53. - restart nginx
  54. - name: upload nginx proxy configuration
  55. template:
  56. src: proxy_nginx.j2
  57. dest: "/etc/nginx/sites-available/{{ config_name }}"
  58. when: is_proxy | bool
  59. notify:
  60. - enable nginx configuration
  61. - restart nginx
  62. - name: add nginx configuration custom templates
  63. template:
  64. src: "roles/{{ parent_role_path }}/templates/{{ item }}.conf.nginx.j2"
  65. dest: "/etc/nginx/sites-available/{{ item }}.conf"
  66. with_items: "{{ config_names }}"
  67. when: config_names is defined and item|bool
  68. - name: enable nginx configuration custom templates
  69. file:
  70. src: "/etc/nginx/sites-available/{{ item }}.conf"
  71. dest: "/etc/nginx/sites-enabled/{{ item }}.conf"
  72. state: link
  73. with_items: "{{ config_names }}"
  74. when: config_names is defined and item|bool
  75. notify: restart nginx
  76. - name: generate nginx configurations from standard template
  77. template:
  78. src: site.j2
  79. dest: "/etc/nginx/sites-available/{{ item.server.file_name }}"
  80. with_items: "{{ nginx_sites }}"
  81. when: nginx_sites is defined and nginx_sites
  82. register: nginx_gen_conf
  83. notify: restart nginx
  84. - name: disable ssl configurations with pending cert issuing
  85. file:
  86. path: "/etc/nginx/sites-enabled/{{ item.item.server.file_name }}"
  87. state: absent
  88. with_items: "{{ nginx_gen_conf.results }}"
  89. when:
  90. - item | changed
  91. - item.item.letsencrypt is defined
  92. - name: enable nginx configurations used for letsencrypt challenge
  93. file:
  94. path: "/etc/nginx/sites-enabled/{{ item.server.file_name }}"
  95. state: link
  96. src: "/etc/nginx/sites-available/{{ item.server.file_name }}"
  97. with_items: "{{ nginx_sites }}"
  98. when: letsencrypt|bool and item.use_for_challenge is defined and item.use_for_challenge|bool and nginx_sites is defined and nginx_sites
  99. - name: restart nginx to start enabled configurations used for letsencrypt
  100. service:
  101. name: nginx
  102. state: restarted
  103. when: letsencrypt|bool
  104. - name: provision letsencrypt account private key
  105. openssl_privatekey:
  106. path: "{{ letsencrypt_account_key }}"
  107. when: letsencrypt|bool
  108. - name: provision ssl cert/key(s) with letsencrypt
  109. include: letsencrypt.yaml
  110. with_items: "{{ nginx_sites }}"
  111. when: letsencrypt|bool and item.letsencrypt is defined and nginx_sites is defined and nginx_sites
  112. - name: enable nginx configuration generated from standard template
  113. file:
  114. path: "/etc/nginx/sites-enabled/{{ item.server.file_name }}"
  115. state: link
  116. src: "/etc/nginx/sites-available/{{ item.server.file_name }}"
  117. with_items: "{{ nginx_sites }}"
  118. when: nginx_sites is defined and nginx_sites
  119. notify: restart nginx