- name: "Remove all directories" file: path: "/var/www/{{ item }}" state: absent with_items: - "{{ project_name }}" when: "project_name is defined and project is not defined" vars: ansible_become: yes ansible_become_method: sudo ansible_become_password: "{{ sudo_password }}" - name: "Remove single directory" file: path: "/var/www/{{ project }}" state: absent when: "project is defined" vars: ansible_become: yes ansible_become_method: sudo ansible_become_password: "{{ sudo_password }}"