---
- name: Check if local Drush configuration folder exists.
  stat:
    path: ~/.drush
  register: local_drush_config_folder
  delegate_to: 127.0.0.1
  become: no
  when: configure_drush_aliases

- name: Create Drush configuration folder if it doesn't exist.
  file:
    path: ~/.drush
    state: directory
  delegate_to: 127.0.0.1
  become: no
  when: configure_drush_aliases and (local_drush_config_folder.stat.exists == false)

# Note that this doesn't work for Windows, since Ansible's running in the VM.
- name: Configure host machine drush aliases.
  template:
    src: "{{ drush_aliases_host_template }}"
    dest: "~/.drush/{{ vagrant_machine_name }}.aliases.drushrc.php"
  delegate_to: 127.0.0.1
  become: no
  when: configure_drush_aliases

- name: Ensure drush directory exists for vagrant user inside VM.
  file: 'path="~/.drush" state=directory'
  become: no

- name: Configure drush aliases for vagrant user inside VM.
  template:
    src: "{{ drush_aliases_guest_template }}"
    dest: "~/.drush/{{ vagrant_machine_name }}.aliases.drushrc.php"
  become: no
  when: configure_drush_aliases

- name: Ensure drush directory exists for root user inside VM.
  file: 'path="~/.drush" state=directory'

- name: Configure drush aliases for root user inside VM.
  template:
    src: "{{ drush_aliases_guest_template }}"
    dest: "~/.drush/{{ vagrant_machine_name }}.aliases.drushrc.php"
  when: configure_drush_aliases
