---
- name: Add backwards-compatibility shims.
  include: backwards-compatibility.yml
  static: no

- name: Check if Drupal is already set up.
  stat: "path={{ drupal_core_path }}/index.php"
  register: drupal_site
  ignore_errors: true

- name: Define drush_path if it's not already defined.
  set_fact:
    drush_path: drush
  when: drush_path is not defined

- name: Define drupal_site_exists.
  set_fact:
    drupal_site_exists: "{{ drupal_site.stat.exists|default(false) }}"

# Deploy Drupal if configured.
- include: tasks/deploy.yml
  when: drupal_deploy

- name: Define drupal_deploy_updated
  set_fact:
    drupal_deploy_updated: "{{ drupal_deploy_repo_updated.changed|default(false) }}"

# Run update tasks if Drupal was updated.
- include: tasks/update.yml
  when: drupal_deploy_updated and drupal_site_exists
  static: no

# Build makefile if configured.
- include: tasks/build-makefile.yml
  when: drupal_build_makefile
  static: no

# Build with composer if configured.
- include: tasks/build-composer.yml
  when: drupal_build_composer
  static: no

# Build a composer project if configured.
- include: tasks/build-composer-project.yml
  when: drupal_build_composer_project
  static: no

# Set Drush variables.
- name: Check if a project specific Drush binary exists.
  stat: "path={{ drupal_composer_install_dir }}/vendor/drush/drush/drush"
  register: drush_vendor_bin
  ignore_errors: true

- name: Use project specific Drush if available.
  set_fact:
    drush_path: "{{ drupal_composer_install_dir }}/vendor/drush/drush/drush"
  when: drush_vendor_bin.stat.exists

# Install site if configured.
- include: tasks/install-site.yml
  when: drupal_install_site
  static: no
