--- - name: "[NGINX] - Create vhosts" template: src: etc/nginx/sites-available/{{ item.template }}.j2 dest: "{{ nginx_etc_dir }}/sites-available/{{ item.name }}" with_items: "{{ nginx_vhosts }}" notify: - reload nginx when: item.state is defined and item.state != 'delete' - name: "[NGINX] - Delete vhosts" file: path: "{{ nginx_etc_dir }}/sites-available/{{ item.name }}" state: absent with_items: "{{ nginx_vhosts }}" notify: - reload nginx when: item.state is defined and item.state == 'delete' - name: "[NGINX] - Enable vhosts" file: src: "{{ nginx_etc_dir }}/sites-available/{{ item.name }}" dest: "{{ nginx_etc_dir }}/sites-enabled/{{ item.name }}" state: link with_items: "{{ nginx_vhosts }}" notify: - reload nginx when: item.state is defined and item.state == 'enable' - name: "[NGINX] - Disable vhosts" file: path: "{{ nginx_etc_dir}}/sites-enabled/{{ item.name }}" state: absent with_items: "{{ nginx_vhosts }}" notify: - reload nginx when: item.state is defined and (item.state == 'disable' or item.state == 'delete') - name: "[NGINX] - Delete default vhost when explicitely defined" file: path: "{{ nginx_etc_dir }}/sites-enabled/default" state: absent notify: - reload nginx when: nginx_default_vhost is not none