Shouldn't this run by default?

Before rushing to create a new issue in the Trelis repository, I want to clear this up in forum first.

So by default WordPress is installed for all sites on ansible-playbook run, according to these lines:


(No explicit site_install: true seems to be necessary because of the line
when: item.value.site_install | default(true)).

However, on a deploy on a freshly provisoned server the following error occurs:

non-zero return code
Error: The site you have requested is not installed.
Run `wp core install`.
fatal: [staging-v]: FAILED! => {"changed": true, "cmd": ["wp", "core", "language", "install", "de_DE"], "delta": "0:00:00.091690", "end": "2018-03-17 01:13:31.859997", "rc": 1, "start": "2018-03-17 01:13:31.768307", "stderr_lines": ["Error: The site you have requested is not installed.", "Run `wp core install`."], "stdout": "", "stdout_lines": []}

This happens when a new language should be installed.

As current workaround, an extra wp core install task was
added to deploy hook prior installing a new language.
But this shouldn’t be actually necessary because the site should already
have been installed for all sites during prior provisioning?

Edit: wordpress-install is only included in dev environment. Why not also in staging and production environments?

How can I run this in a *-finalize-after task?
The variables must be different so the site-specific ones are used (not inside loop):

- name: Install WP
  command: wp core {{ item.value.multisite.enabled | default(false) | ternary('multisite-install', 'install') }}
           --allow-root
           --url="{{ site_env.wp_home }}"
           {% if item.value.multisite.enabled | default(false) %}
           --base="{{ item.value.multisite.base_path | default('/') }}"
           --subdomains="{{ item.value.multisite.subdomains | default('false') }}"
           {% endif %}
           --title="{{ item.value.site_title | default(item.key) }}"
           --admin_user="{{ item.value.admin_user | default('admin') }}"
           --admin_password="{{ vault_wordpress_sites[item.key].admin_password }}"
  args:
    chdir: "{{ deploy_helper.current_path }}"
  register: wp_install
  changed_when: "'WordPress is already installed.' not in wp_install.stdout and 'The network already exists.' not in wp_install.stdout"

Now I need to access the right vault keys, or alternatively,
the project key for retrieving the right vault keys
(for admin_password) from vault_wordpress_sites.

- name: Install WP
  command: wp core {{ project.multisite.enabled | default(false) | ternary('multisite-install', 'install') }}
           --allow-root
           --url="{{ site_env.wp_home }}"
           {% if project.multisite.enabled | default(false) %}
           --base="{{ project.multisite.base_path | default('/') }}"
           --subdomains="{{ project.multisite.subdomains | default('false') }}"
           {% endif %}
           --title="{{ project.site_title | default(item.key) }}"
           --admin_user="{{ project.admin_user | default('admin') }}"
           --admin_password="{{ vault_wordpress_sites[item.key].admin_password }}"

Shouldn’t this run by default?

No. You can look at previous threads on this for related discussions

Maybe this is helpful for someone, this I am using now in *-finalize-after deploy hook for preparing WordPress in order to install other languages on a yet non-prepared site:

- name: Install WP (required for installing languages on empty site)
  command: wp core {{ project.multisite.enabled | default(false) | ternary('multisite-install', 'install') }}
           --allow-root
           --url="{{ site_env.wp_home }}"
           {% if project.multisite.enabled | default(false) %}
           --base="{{ project.multisite.base_path | default('/') }}"
           --subdomains="{{ project.multisite.subdomains | default('false') }}"
           {% endif %}
           --title="{{ project.site_title | default(site) }}"
           --admin_user="{{ project.admin_user | default('admin') }}"
           --admin_password="{{ vault_wordpress_sites[site].admin_password }}"
           --admin_email="{{ project.admin_email }}"
  args:
    chdir: "{{ deploy_helper.current_path }}"
  register: wp_install
  changed_when: "'WordPress is already installed.' not in wp_install.stdout and 'The network already exists.' not in wp_install.stdout"