---
-
  name: Ensure drupal_deploy_dir directory exists.
  ansible.builtin.file:
    path: "{{ drupal_deploy_dir }}"
    state: directory
    mode: "0775"
    owner: "{{ drupal_core_owner }}"
    group: "{{ drupal_core_owner }}"
  when: drupal_composer_path and not drupal_site_exists

-
  name: Check out Drupal to the docroot.
  ansible.builtin.git:
    repo: "{{ drupal_deploy_repo }}"
    version: "{{ drupal_deploy_version }}"
    update: "{{ drupal_deploy_update }}"
    force: true
    dest: "{{ drupal_deploy_dir }}"
    accept_hostkey: "{{ drupal_deploy_accept_hostkey }}"
  register: drupal_deploy_repo_updated
  notify: Clear opcache
  become: "{{ drupal_core_owner_become }}"
  become_user: "{{ drupal_core_owner }}"

-
  name: Check if a composer.json file is present.
  ansible.builtin.stat:
    path: "{{ drupal_deploy_dir }}/composer.json"
  register: drupal_deploy_composer_file

-
  name: Run composer install if composer.json is present.
  community.general.composer:
    command: install
    working_dir: "{{ drupal_deploy_dir }}"
    no_dev: "{{ drupal_composer_no_dev }}"
  when:
    - drupal_deploy_composer_file.stat.exists
    - drupal_deploy_composer_install
  become: "{{ drupal_core_owner_become }}"
  become_user: "{{ drupal_core_owner }}"
