vhosts.yml 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. ---
  2. - name: Remove default nginx vhost config file (if configured).
  3. file:
  4. path: "{{ nginx_default_vhost_path }}"
  5. state: absent
  6. when: nginx_remove_default_vhost
  7. notify: reload nginx
  8. - name: Ensure nginx_vhost_path exists.
  9. file:
  10. path: "{{ nginx_vhost_path }}"
  11. state: directory
  12. notify: reload nginx
  13. - name: Create self-signed ssl certificates.
  14. x509_certificate:
  15. key_path: '/etc/ssl/private/{{vhost.server_name}}.key'
  16. cert_path: '/etc/ssl/certs/{{vhost.server_name}}.pem'
  17. common_name: '{{vhost.server_name}}'
  18. organization_name: '{{vhost.ssl_cert_organization_name|default(None)}}'
  19. when: vhost.ssl | default(false)
  20. loop_control:
  21. loop_var: vhost
  22. with_items: '{{nginx_vhosts|default([])}}'
  23. register: vhosts_x509
  24. # http://unix.stackexchange.com/questions/247418/do-i-need-to-restart-nginx-if-i-renew-my-security-certificates#comment548097_247460
  25. notify: reload nginx
  26. - name: Download ssl certificates.
  27. fetch:
  28. src: '{{item.cert_path}}'
  29. flat: yes
  30. dest: '{{nginx_ssl_cert_download_path_prefix}}/{{item.subject_common_name}}'
  31. fail_on_missing: yes
  32. validate_checksum: yes
  33. when: item.subject_common_name is defined and nginx_ssl_cert_download_path_prefix is defined
  34. with_items: '{{vhosts_x509.results}}'
  35. - name: Add managed vhost config file (if any vhosts are configured).
  36. template:
  37. src: vhosts.j2
  38. dest: "{{ nginx_vhost_path }}/{{ nginx_vhosts_filename }}"
  39. mode: 0644
  40. when: nginx_vhosts|length > 0
  41. notify: reload nginx
  42. - name: Remove managed vhost config file (if no vhosts are configured).
  43. file:
  44. path: "{{ nginx_vhost_path }}/{{ nginx_vhosts_filename }}"
  45. state: absent
  46. when: nginx_vhosts|length == 0
  47. notify: reload nginx