vhosts.yml 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. when: vhost.ssl | default(false)
  19. loop_control:
  20. loop_var: vhost
  21. with_items: '{{nginx_vhosts|default([])}}'
  22. register: vhosts_x509
  23. - name: Download ssl certificates.
  24. fetch:
  25. src: '{{item.cert_path}}'
  26. flat: yes
  27. dest: '{{nginx_ssl_cert_download_path_prefix}}/{{item.subject_common_name}}'
  28. fail_on_missing: yes
  29. validate_checksum: yes
  30. when: item.subject_common_name is defined and nginx_ssl_cert_download_path_prefix is defined
  31. with_items: '{{vhosts_x509.results}}'
  32. - name: Add managed vhost config file (if any vhosts are configured).
  33. template:
  34. src: vhosts.j2
  35. dest: "{{ nginx_vhost_path }}/{{ nginx_vhosts_filename }}"
  36. mode: 0644
  37. when: nginx_vhosts|length > 0
  38. notify: reload nginx
  39. - name: Remove managed vhost config file (if no vhosts are configured).
  40. file:
  41. path: "{{ nginx_vhost_path }}/{{ nginx_vhosts_filename }}"
  42. state: absent
  43. when: nginx_vhosts|length == 0
  44. notify: reload nginx