07_manager_ops.ymlΒΆ

---
- name: πŸ”Ž Check if {{ WORDPRESS_CONFIG_FILE }} exists in WordPress
  shell: >
    container exec -u {{ WORDPRESS_USER }} {{ WORDPRESS_CONTAINER_ADDRESS }} test -f {{ WORDPRESS_CONFIG_PATH }}
  register: wp_config_file_exists
  changed_when: false
  failed_when: false

- name: 🩹 Patch WordPress {{ WORDPRESS_CONFIG_FILE }} with updated DB credentials
  include_tasks: 01_patch_config.yml
  when: wp_config_file_exists.rc == 0

- name: "πŸ“¦ Install wordpress"
  include_tasks: 02_install.yml

- name: "πŸ”„ Convert to Multisite when opted in"
  include_tasks: 03_multisite.yml
  when: WORDPRESS_MULTISITE_ENABLED | bool

- name: "πŸ›‘ Assert every required addon is claimed by an install path"
  ansible.builtin.assert:
    that:
      - WORDPRESS_ADDONS_REQUIRED | difference(WORDPRESS_ADDONS_INSTALLED) | length == 0
    fail_msg: >-
      Required addon(s)
      {{ WORDPRESS_ADDONS_REQUIRED | difference(WORDPRESS_ADDONS_INSTALLED) | join(', ') }}
      are declared in meta/addons/ but no install loop selects them; their
      `mechanism` must be `plugin` or `mu_plugin` to be installed at all.

- name: "πŸ“¦ Install declared mu-plugins"
  include_tasks: 04_mu_plugins.yml

- name: "πŸ” Iterate through WordPress plugins"
  include_tasks: 05_enable_plugin.yml
  loop: "{{ WORDPRESS_PLUGINS }}"
  loop_control:
    loop_var: wordpress_plugin
    label: "{{ wordpress_plugin.key }}"
  vars:
    plugin_name: "{{ wordpress_plugin.key }}"
    plugin_enabled: "{{ wordpress_plugin.value.enabled | bool }}"
    plugin_task_path: "{{ [role_path, 'tasks/addons', plugin_name  ~ '.yml' ] | path_join }}"
  when: plugin_enabled | bool

- name: "⬇️ Read the WordPress options services.wordpress.options pins"
  shell: >
    container exec -u {{ WORDPRESS_USER }} {{ WORDPRESS_CONTAINER_ADDRESS }}
    wp option get {{ item.key | quote }} --format=json
    --path={{ WORDPRESS_DOCKER_HTML_PATH }}
  loop: "{{ WORDPRESS_OPTIONS | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  register: wp_options_stored
  changed_when: false
  failed_when: >-
    wp_options_stored.rc != 0
    and 'Could not get' not in wp_options_stored.stderr

- name: "πŸ”§ Write each pinned WordPress option whose stored value differs"
  shell: >
    container exec -u {{ WORDPRESS_USER }} {{ WORDPRESS_CONTAINER_ADDRESS }}
    wp option update {{ item.item.key | quote }} {{ item.item.value | to_json | quote }}
    --format=json --path={{ WORDPRESS_DOCKER_HTML_PATH }}
  loop: "{{ wp_options_stored.results }}"
  loop_control:
    label: "{{ item.item.key }}"
  when: item | wordpress_option_drifted
  register: wp_options_written
  changed_when: >-
    'option is unchanged.' not in wp_options_written.stdout

- name: "🚿 Flush the rewrite rules after a pinned option changed"
  shell: >
    container exec -u {{ WORDPRESS_USER }} {{ WORDPRESS_CONTAINER_ADDRESS }}
    wp rewrite flush --path={{ WORDPRESS_DOCKER_HTML_PATH }}
  when: wp_options_written is changed

- name: "🌍 Verify FreedomTranslate posts to the translation gateway"
  when: WORDPRESS_TRANSLATE_ENABLED | bool
  block:
    - name: "πŸ”Ž Read the gateway URL back out of WordPress"
      ansible.builtin.shell: >
        container exec -u {{ WORDPRESS_USER }} {{ WORDPRESS_CONTAINER_ADDRESS }}
        wp option get freedomtranslate_api_url --path={{ WORDPRESS_DOCKER_HTML_PATH }}
      register: wordpress_translate_readback
      changed_when: false

    - name: "πŸ›‘ Refuse a plugin that translates somewhere else"
      ansible.builtin.assert:
        that:
          - (wordpress_translate_readback.stdout | trim) == WORDPRESS_TRANSLATE_ENDPOINT
        fail_msg: >-
          freedomtranslate-wp posts to '{{ wordpress_translate_readback.stdout | trim }}'
          instead of {{ WORDPRESS_TRANSLATE_ENDPOINT }}, so the content would be
          translated outside this deployment or not at all.

- name: πŸ” Detect if WordPress is Multisite
  shell: >
    container exec -u {{ WORDPRESS_USER }} {{ WORDPRESS_CONTAINER_ADDRESS }}
    wp eval 'echo (int) is_multisite();' --path={{ WORDPRESS_DOCKER_HTML_PATH }}
  register: wp_is_multisite
  changed_when: false

- name: "πŸ”„ Update Single Side WordPress domain"
  include_tasks: 06_update_domain.yml
  when: (wp_is_multisite.stdout | trim) == '0'
  vars:
    wp_new_url: "{{ WORDPRESS_URL }}"

- name: "🎨 Apply or withdraw the corporate design"
  include_tasks: 08_design.yml

- name: "πŸ“§ Verify the relay accepted WordPress's startup mail"
  when: lookup('config', application_id, 'services.email.enabled', false) | bool
  block:
    - name: "⏳ Wait for the delivery marker the healthcheck writes"
      shell: >
        container exec {{ WORDPRESS_CONTAINER_ADDRESS }} test -f {{ lookup('container_mail_marker') }}
      register: wordpress_smoke_mail
      changed_when: false
      failed_when: false
      retries: 30
      delay: 5
      until: wordpress_smoke_mail.rc == 0

    - name: "πŸ›‘ Report a relay that refused every attempt"
      ansible.builtin.assert:
        that: wordpress_smoke_mail.rc == 0
        fail_msg: >-
          WordPress never delivered its startup mail. The healthcheck writes
          {{ lookup('container_mail_marker') }} only after msmtp exits 0, so
          the relay refused every attempt. Its reason is in the container's
          State.Health.Log; liveness itself is unaffected, which is why the
          stack still converged.