vhosts.yml 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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: Add managed vhost config file (if any vhosts are configured).
  24. template:
  25. src: vhosts.j2
  26. dest: "{{ nginx_vhost_path }}/{{ nginx_vhosts_filename }}"
  27. mode: 0644
  28. when: nginx_vhosts|length > 0
  29. notify: reload nginx
  30. - name: Remove managed vhost config file (if no vhosts are configured).
  31. file:
  32. path: "{{ nginx_vhost_path }}/{{ nginx_vhosts_filename }}"
  33. state: absent
  34. when: nginx_vhosts|length == 0
  35. notify: reload nginx