mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-30 23:38:13 +02:00
70 lines
2.8 KiB
YAML
70 lines
2.8 KiB
YAML
---
|
|
# Updates WordPress single-site URLs and normalizes DB references.
|
|
# Expects: wp_new_url (passed from main.yml), WORDPRESS_USER/container/docker_html_path.
|
|
|
|
- name: Get current 'home' URL
|
|
command: >
|
|
docker exec -u {{ WORDPRESS_USER }} {{ WORDPRESS_CONTAINER }}
|
|
wp option get home --path={{ WORDPRESS_DOCKER_HTML_PATH }}
|
|
register: wp_home
|
|
changed_when: false
|
|
failed_when: false
|
|
|
|
- name: Get current 'siteurl'
|
|
command: >
|
|
docker exec -u {{ WORDPRESS_USER }} {{ WORDPRESS_CONTAINER }}
|
|
wp option get siteurl --path={{ WORDPRESS_DOCKER_HTML_PATH }}
|
|
register: wp_siteurl
|
|
changed_when: false
|
|
failed_when: false
|
|
|
|
- name: Update 'home' (if needed)
|
|
vars:
|
|
wp_new_url_norm: "{{ wp_new_url | regex_replace('/+$','') }}"
|
|
wp_home_norm: "{{ wp_home.stdout | regex_replace('/+$','') }}"
|
|
command: >
|
|
docker exec -u {{ WORDPRESS_USER }} {{ WORDPRESS_CONTAINER }}
|
|
wp option update home "{{ wp_new_url_norm }}" --path={{ WORDPRESS_DOCKER_HTML_PATH }}
|
|
when: wp_home_norm != wp_new_url_norm
|
|
|
|
- name: Update 'siteurl' (if needed)
|
|
vars:
|
|
wp_new_url_norm: "{{ wp_new_url | regex_replace('/+$','') }}"
|
|
wp_siteurl_norm: "{{ wp_siteurl.stdout | regex_replace('/+$','') }}"
|
|
command: >
|
|
docker exec -u {{ WORDPRESS_USER }} {{ WORDPRESS_CONTAINER }}
|
|
wp option update siteurl "{{ wp_new_url_norm }}" --path={{ WORDPRESS_DOCKER_HTML_PATH }}
|
|
when: wp_siteurl_norm != wp_new_url_norm
|
|
|
|
- name: Search-replace old → new URLs in DB (single site)
|
|
vars:
|
|
wp_old_url_norm: "{{ wp_home.stdout | regex_replace('/+$','') }}"
|
|
wp_new_url_norm: "{{ wp_new_url | regex_replace('/+$','') }}"
|
|
command: >
|
|
docker exec -u {{ WORDPRESS_USER }} {{ WORDPRESS_CONTAINER }}
|
|
wp search-replace "{{ wp_old_url_norm }}" "{{ wp_new_url_norm }}"
|
|
--skip-columns=guid --all-tables-with-prefix --precise
|
|
--path={{ WORDPRESS_DOCKER_HTML_PATH }}
|
|
register: wp_sr_domain
|
|
changed_when: "{{ ('Success: Made 0 replacements.' not in wp_sr_domain.stdout) | bool }}"
|
|
|
|
- name: Normalize scheme to https if needed (http → https)
|
|
vars:
|
|
domain_only: "{{ (wp_new_url | regex_replace('^https?://','')) | regex_replace('/+$','') }}"
|
|
http_url: "http://{{ domain_only }}"
|
|
https_url: "https://{{ domain_only }}"
|
|
command: >
|
|
docker exec -u {{ WORDPRESS_USER }} {{ WORDPRESS_CONTAINER }}
|
|
wp search-replace "{{ http_url }}" "{{ https_url }}"
|
|
--skip-columns=guid --all-tables-with-prefix --precise
|
|
--path={{ WORDPRESS_DOCKER_HTML_PATH }}
|
|
register: wp_sr_scheme
|
|
changed_when: "{{ ('Success: Made 0 replacements.' not in wp_sr_scheme.stdout) | bool }}"
|
|
when: WEB_PORT == 443
|
|
|
|
- name: Flush caches and rewrite rules
|
|
command: >
|
|
docker exec -u {{ WORDPRESS_USER }} {{ WORDPRESS_CONTAINER }} bash -lc
|
|
"wp cache flush --path={{ WORDPRESS_DOCKER_HTML_PATH }} &&
|
|
wp rewrite flush --hard --path={{ WORDPRESS_DOCKER_HTML_PATH }}"
|