---
- name: Check if site is already installed.
  command: >
    {{ drush_path }} status bootstrap
    chdir={{ drupal_core_path }}
  register: drupal_site_installed
  failed_when: false
  changed_when: false
  become: no

- name: Install Drupal with drush.
  command: >
    {{ drush_path }} site-install {{ drupal_install_profile | default('standard') }} -y
    --site-name="{{ drupal_site_name }}"
    --account-name={{ drupal_account_name }}
    --account-pass={{ drupal_account_pass }}
    --db-url=mysql://{{ drupal_mysql_user }}:{{ drupal_mysql_password }}@localhost/{{ mysql_databases[0].name }}
    {{ drupal_site_install_extra_args | default([]) | join(" ") }}
    chdir={{ drupal_core_path }}
  notify: restart webserver
  when: "'Successful' not in drupal_site_installed.stdout"
  become: no

- name: Install configured modules with drush.
  command: >
    {{ drush_path }} pm-enable -y {{ drupal_enable_modules | join(" ") }}
    chdir={{ drupal_core_path }}
  when: "'Successful' not in drupal_site_installed.stdout"
  become: no

---
- name: Check if site is already installed.
  command: >
    {{ drush_path }} status bootstrap
    chdir={{ drupal_core_path }}
  register: drupal_site_installed
  failed_when: "drupal_site_installed.stdout is undefined"
  changed_when: false
  become: no

- name: Install Drupal with drush.
  command: >
    {{ drush_path }} site-install {{ drupal_install_profile | default('standard') }} -y
    --site-name="{{ drupal_site_name }}"
    --account-name={{ drupal_account_name }}
    --account-pass={{ drupal_account_pass }}
    --db-url=mysql://{{ drupal_mysql_user }}:{{ drupal_mysql_password }}@localhost/{{ mysql_databases[0].name }}
    {{ drupal_site_install_extra_args | default([]) | join(" ") }}
    chdir={{ drupal_core_path }}
  notify: restart webserver
  when: "'Successful' not in drupal_site_installed.stdout"
  become: no

- name: Install configured modules with drush.
  command: >
    {{ drush_path }} pm-enable -y {{ drupal_enable_modules | join(" ") }}
    chdir={{ drupal_core_path }}
  when: "'Successful' not in drupal_site_installed.stdout"
  become: no

Fix misleading error message when attempting to install drupal without a codebase
Fix misleading error message when attempting to install drupal without a codebase
