---
-
  name: Delete old /tmp/composer-project
  ansible.builtin.file:
    path: "/tmp/composer-project"
    state: absent
  when: not drupal_site_exists

-
  name: Generate Drupal project with composer package in /tmp/composer-project (this may take a while).
  ansible.builtin.command: >
    {{ composer_path }} create-project {{ drupal_composer_project_package }} /tmp/composer-project {{ drupal_composer_project_options | default('--prefer-dist --no-interaction') }}
  when: not drupal_site_exists
  become: false
  changed_when: false
  environment:
    COMPOSER_PROCESS_TIMEOUT: "1200"
    COMPOSER_MEMORY_LIMIT: '-1'

-
  name: Ensure drupal_composer_install_dir directory has proper permissions.
  ansible.builtin.file:
    path: "{{ drupal_composer_install_dir }}"
    state: directory
    owner: "{{ drupal_core_owner }}"
    group: "{{ drupal_core_owner }}"
    mode: "0775"
  when: not drupal_site_exists
  failed_when: false

-
  name: Move Drupal project files to drupal_composer_install_dir (this may take a while).
  ansible.builtin.command: >
    cp -r /tmp/composer-project/. {{ drupal_composer_install_dir }}/
    creates={{ drupal_core_path }}/index.php
  become: false
  when: not drupal_site_exists

-
  name: Install dependencies with composer require (this may take a while).
  community.general.composer:
    command: require
    arguments: "{{ item }}"
    working_dir: "{{ drupal_composer_install_dir }}"
  with_items: "{{ drupal_composer_dependencies | default([]) }}"
  become: false
  environment:
    COMPOSER_PROCESS_TIMEOUT: "1200"
    COMPOSER_MEMORY_LIMIT: '-1'
