Build after acorn optimize task fails

  • Trellis 1.16.0 - July 18th, 2022
  • Sage 10.2.0- July 19th, 2022
  • Bedrock 1.20.2 - 2022-08-31

I get a deploy error in a fresh Trellis setup. somebody with this issue?

# Placeholder `deploy_build_after` hook
# ⚠️ This example assumes your theme is using Sage 10
# Uncomment the lines below if you are using Sage 10
# ---

- name: Run Acorn optimize
  command: wp acorn optimize
  args:
    chdir: "{{ deploy_helper.new_release_path }}"

After uncomment this task, I get this error:

TASK [deploy : Run Acorn optimize] *********************************************
System info:
  Ansible 2.13.3; Darwin
  Trellis 1.16.0: July 18th, 2022
---------------------------------------------------
non-zero return code
Error: The site you have requested is not installed.
Run `wp core install` to create database tables.
fatal: [157.230.105.211]: FAILED! => {"changed": true, "cmd": ["wp", "acorn", "optimize"], "delta": "0:00:00.313466", "end": "2022-09-13 15:44:14.720100", "rc": 1, "start": "2022-09-13 15:44:14.406634", "stderr_lines": ["Error: The site you have requested is not installed.", "Run `wp core install` to create database tables."], "stdout": "", "stdout_lines": []}

I think we need to update that task to be conditional (to only run if WP is already installed), but you can uncomment on your first deploy to get up and running for now

After you’ve got WordPress installed on the remote server you should be okay to re-add it

5 Likes

Ran into this issue again and tried to wrap my head around a proper conditional – first thought was to utilize

when: wp_installed is defined and wp_installed.rc == 0

but that variable is only being set in the finalize-before-step and thus not available yet…

So the only solution I could come up with would be to run a full check like

- name: WordPress Installed (non-multisite)?
  block:
    - name: "Invoke 'wp core is-installed' command"
      command: wp core is-installed --skip-plugins --skip-themes
      args:
        chdir: "{{ deploy_helper.current_path }}"
      register: acorn_optimize_wp_installed_singlesite
      changed_when: false
      failed_when: acorn_optimize_wp_installed_singlesite.stderr | length > 0 or acorn_optimize_wp_installed_singlesite.rc > 1

    - name: Set "WordPress installed?" result variable (from non-multisite)
      set_fact:
        acorn_optimize_wp_installed: "{{ acorn_optimize_wp_installed_singlesite }}"
  when:
    - not project.multisite.enabled | default(false)

- name: WordPress Installed (multisite)?
  block:
    - name: "Invoke 'wp core is-installed' command"
      command: wp core is-installed --skip-plugins --skip-themes --require={{ deploy_helper.shared_path }}/tmp_multisite_constants.php
      args:
        chdir: "{{ deploy_helper.current_path }}"
      register: acorn_optimize_wp_installed_multisite
      changed_when: false
      failed_when: (acorn_optimize_wp_installed_multisite.stderr | length > 0 and acorn_optimize_wp_installed_multisite.stderr is not match(php_needle_warning)) or acorn_optimize_wp_installed_multisite.rc > 1

    - name: Set "WordPress installed?" result variable (from multisite)
      set_fact:
        acorn_optimize_wp_installed: "{{ acorn_optimize_wp_installed_multisite }}"
  when:
    - project.multisite.enabled | default(false)

- name: Run Acorn optimize
  command: wp acorn optimize
  args:
    chdir: "{{ deploy_helper.new_release_path }}"
  when: acorn_optimize_wp_installed.rc == 0

but that seems a bit over the top as these checks are performed on every deploy whilst we’d only need this once / in the beginning…

Your take on this?