---
-
  name: Copy drush makefile into place.
  ansible.builtin.copy:
    src: "{{ drush_makefile_path }}"
    dest: /tmp/drupal.make.yml
    mode: "0644"
  when: not drupal_site_exists

-
  name: Ensure drupal_core_path directory exists.
  ansible.builtin.file:
    path: "{{ drupal_core_path }}"
    state: directory
    recurse: true
    mode: "0775"
  become: false
  when: not drupal_site_exists

-
  name: Generate Drupal site with drush makefile.
  changed_when: false
  ansible.builtin.command: >
    {{ drush_path }} make -y /tmp/drupal.make.yml {{ drush_make_options }}
    chdir={{ drupal_core_path }}
  when: not drupal_site_exists
  become: false

-
  name: Check if a composer.json file is present.
  ansible.builtin.stat:
    path: "{{ drupal_core_path }}/composer.json"
  register: drupal_core_composer_file
  when: not drupal_site_exists

-
  name: Run composer install if composer.json is present.
  ansible.builtin.command: >
    composer install
    chdir={{ drupal_core_path }}
  when: not drupal_site_exists and drupal_core_composer_file.stat.exists
  changed_when: false
  become: false
