mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 23:08:06 +02:00
refactor(web-app-wordpress): unify variable naming to uppercase WORDPRESS_* style
- Replaced all lowercase wordpress_* variables with uppercase WORDPRESS_* equivalents - Ensured consistency across tasks, templates, and vars - Improves readability and aligns with naming conventions Conversation: https://chatgpt.com/share/68af29b5-8e7c-800f-bd12-48cc5956311c
This commit is contained in:
@@ -1,27 +1,27 @@
|
||||
# The seeds need to be executed as root, because www-data isn't allowed to create files in the wordpress directory
|
||||
|
||||
- name: Update DB host in {{ wordpress_config_file }}
|
||||
- name: Update DB host in {{ WORDPRESS_CONFIG_FILE }}
|
||||
command: >
|
||||
docker exec --user root {{ wordpress_container }}
|
||||
sed -i "s/define(\s*'DB_HOST'\s*,\s*'[^']*'\s*);/define( 'DB_HOST', '{{ database_host }}:{{ database_port }}' );/i" {{ wordpress_docker_conf_path }}
|
||||
docker exec --user root {{ WORDPRESS_CONTAINER }}
|
||||
sed -i "s/define(\s*'DB_HOST'\s*,\s*'[^']*'\s*);/define( 'DB_HOST', '{{ database_host }}:{{ database_port }}' );/i" {{ WORDPRESS_DOCKER_CONF_PATH }}
|
||||
notify: docker compose restart
|
||||
|
||||
- name: Update DB name in {{ wordpress_config_file }}
|
||||
- name: Update DB name in {{ WORDPRESS_CONFIG_FILE }}
|
||||
command: >
|
||||
docker exec --user root {{ wordpress_container }}
|
||||
sed -i "s/define(\s*'DB_NAME'\s*,\s*'[^']*'\s*);/define( 'DB_NAME', '{{ database_name }}' );/i" {{ wordpress_docker_conf_path }}
|
||||
docker exec --user root {{ WORDPRESS_CONTAINER }}
|
||||
sed -i "s/define(\s*'DB_NAME'\s*,\s*'[^']*'\s*);/define( 'DB_NAME', '{{ database_name }}' );/i" {{ WORDPRESS_DOCKER_CONF_PATH }}
|
||||
notify: docker compose restart
|
||||
|
||||
- name: Update DB user in {{ wordpress_config_file }}
|
||||
- name: Update DB user in {{ WORDPRESS_CONFIG_FILE }}
|
||||
command: >
|
||||
docker exec --user root {{ wordpress_container }}
|
||||
sed -i "s/define(\s*'DB_USER'\s*,\s*'[^']*'\s*);/define( 'DB_USER', '{{ database_username }}' );/i" {{ wordpress_docker_conf_path }}
|
||||
docker exec --user root {{ WORDPRESS_CONTAINER }}
|
||||
sed -i "s/define(\s*'DB_USER'\s*,\s*'[^']*'\s*);/define( 'DB_USER', '{{ database_username }}' );/i" {{ WORDPRESS_DOCKER_CONF_PATH }}
|
||||
notify: docker compose restart
|
||||
|
||||
- name: Update DB password in {{ wordpress_config_file }}
|
||||
- name: Update DB password in {{ WORDPRESS_CONFIG_FILE }}
|
||||
command: >
|
||||
docker exec --user root {{ wordpress_container }}
|
||||
sed -i "s/define(\s*'DB_PASSWORD'\s*,\s*'[^']*'\s*);/define( 'DB_PASSWORD', '{{ database_password }}' );/i" {{ wordpress_docker_conf_path }}
|
||||
docker exec --user root {{ WORDPRESS_CONTAINER }}
|
||||
sed -i "s/define(\s*'DB_PASSWORD'\s*,\s*'[^']*'\s*);/define( 'DB_PASSWORD', '{{ database_password }}' );/i" {{ WORDPRESS_DOCKER_CONF_PATH }}
|
||||
notify: docker compose restart
|
||||
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
||||
|
||||
|
@@ -1,13 +1,13 @@
|
||||
- name: "Run WordPress core install via WP CLI"
|
||||
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
||||
command: >
|
||||
docker exec -u {{ wordpress_user }} {{ wordpress_container }}
|
||||
docker exec -u {{ WORDPRESS_USER }} {{ WORDPRESS_CONTAINER }}
|
||||
wp core install
|
||||
--url="{{ domains | get_url(application_id, WEB_PROTOCOL) }}"
|
||||
--title="{{ applications | get_app_conf(application_id, 'title', True) }}"
|
||||
--admin_user="{{ applications | get_app_conf(application_id, 'users.administrator.username') }}"
|
||||
--admin_password="{{ applications | get_app_conf(application_id, 'credentials.administrator_password', True) }}"
|
||||
--admin_email="{{ applications | get_app_conf(application_id, 'users.administrator.email', True) }}"
|
||||
--path="{{ wordpress_docker_html_path }}"
|
||||
--path="{{ WORDPRESS_DOCKER_HTML_PATH }}"
|
||||
args:
|
||||
chdir: "{{ docker_compose.directories.instance }}"
|
||||
|
@@ -12,7 +12,7 @@
|
||||
command: >
|
||||
docker-compose exec -u www-data -T application
|
||||
wp plugin install {{ plugin_name }} --activate
|
||||
--path={{ wordpress_docker_html_path }}
|
||||
--path={{ WORDPRESS_DOCKER_HTML_PATH }}
|
||||
args:
|
||||
chdir: "{{ docker_compose.directories.instance }}"
|
||||
when: not plugin_task_file.stat.exists
|
||||
|
@@ -1,19 +1,19 @@
|
||||
---
|
||||
# Updates WordPress single-site URLs and normalizes DB references.
|
||||
# Expects: wp_new_url (passed from main.yml), wordpress_user/container/docker_html_path.
|
||||
# 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 }}
|
||||
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 }}
|
||||
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
|
||||
@@ -23,8 +23,8 @@
|
||||
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 }}
|
||||
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)
|
||||
@@ -32,8 +32,8 @@
|
||||
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 }}
|
||||
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)
|
||||
@@ -41,10 +41,10 @@
|
||||
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 }}
|
||||
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 }}
|
||||
--path={{ WORDPRESS_DOCKER_HTML_PATH }}
|
||||
register: wp_sr_domain
|
||||
changed_when: "{{ ('Success: Made 0 replacements.' not in wp_sr_domain.stdout) | bool }}"
|
||||
|
||||
@@ -54,15 +54,15 @@
|
||||
http_url: "http://{{ domain_only }}"
|
||||
https_url: "https://{{ domain_only }}"
|
||||
command: >
|
||||
docker exec -u {{ wordpress_user }} {{ wordpress_container }}
|
||||
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 }}
|
||||
--path={{ WORDPRESS_DOCKER_HTML_PATH }}
|
||||
register: wp_sr_scheme
|
||||
changed_when: "{{ ('Success: Made 0 replacements.' not in wp_sr_scheme.stdout) | bool }}"
|
||||
|
||||
- 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 }}"
|
||||
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 }}"
|
||||
|
@@ -2,11 +2,11 @@
|
||||
- name: "Include role srv-domain-provision for {{ application_id }}"
|
||||
include_role:
|
||||
name: srv-domain-provision
|
||||
loop: "{{ wordpress_domains }}"
|
||||
loop: "{{ WORDPRESS_DOMAINS }}"
|
||||
loop_control:
|
||||
loop_var: domain
|
||||
vars:
|
||||
proxy_extra_configuration: "client_max_body_size {{ wordpress_max_upload_size }};"
|
||||
proxy_extra_configuration: "client_max_body_size {{ WORDPRESS_MAX_UPLOAD_SIZE }};"
|
||||
http_port: "{{ ports.localhost.http[application_id] }}"
|
||||
|
||||
- name: "load docker and db for {{ application_id }}"
|
||||
@@ -21,22 +21,22 @@
|
||||
dest: "{{ docker_compose.directories.instance }}upload.ini"
|
||||
notify: docker compose up
|
||||
|
||||
- name: "Transfering msmtprc to {{ host_msmtp_conf }}"
|
||||
- name: "Transfering msmtprc to {{ WORDPRESS_HOST_MSMTP_CONF }}"
|
||||
template:
|
||||
src: "{{ playbook_dir }}/roles/sys-svc-msmtp/templates/msmtprc.conf.j2"
|
||||
dest: "{{ host_msmtp_conf }}"
|
||||
dest: "{{ WORDPRESS_HOST_MSMTP_CONF }}"
|
||||
notify: docker compose up
|
||||
|
||||
- name: Flush handlers to make {{ wordpress_config_file }} available before patch
|
||||
- name: Flush handlers to make {{ WORDPRESS_CONFIG_FILE }} available before patch
|
||||
meta: flush_handlers
|
||||
|
||||
- name: Check if {{ wordpress_config_file }} exists in WordPress
|
||||
command: docker exec -u {{ wordpress_user }} {{ wordpress_container }} test -f {{ wordpress_config_path }}
|
||||
- name: Check if {{ WORDPRESS_CONFIG_FILE }} exists in WordPress
|
||||
command: docker exec -u {{ WORDPRESS_USER }} {{ WORDPRESS_CONTAINER }} 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
|
||||
- name: Patch WordPress {{ WORDPRESS_CONFIG_FILE }} with updated DB credentials
|
||||
include_tasks: 01_patch_config.yml
|
||||
when: wp_config_file_exists.rc == 0
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
block:
|
||||
- name: "Iterate through WordPress plugins"
|
||||
include_tasks: 03_enable_plugin.yml
|
||||
loop: "{{ wordpress_plugins }}"
|
||||
loop: "{{ WORDPRESS_PLUGINS }}"
|
||||
loop_control:
|
||||
label: "{{ item.key }}"
|
||||
vars:
|
||||
@@ -58,8 +58,8 @@
|
||||
|
||||
- name: Detect if WordPress is Multisite
|
||||
command: >
|
||||
docker exec -u {{ wordpress_user }} {{ wordpress_container }}
|
||||
wp eval 'echo (int) is_multisite();' --path={{ wordpress_docker_html_path }}
|
||||
docker exec -u {{ WORDPRESS_USER }} {{ WORDPRESS_CONTAINER }}
|
||||
wp eval 'echo (int) is_multisite();' --path={{ WORDPRESS_DOCKER_HTML_PATH }}
|
||||
register: wp_is_multisite
|
||||
changed_when: false
|
||||
|
||||
|
@@ -7,9 +7,9 @@
|
||||
# Generate an empty serialized array in the container, then add or update the option
|
||||
command: >
|
||||
docker-compose exec -u www-data -T application bash -lc
|
||||
"serialized_empty_array=$(wp eval 'echo serialize(array());' --path={{ wordpress_docker_html_path }}); \
|
||||
wp option add openid_connect_generic_settings \"$serialized_empty_array\" --path={{ wordpress_docker_html_path }} \
|
||||
|| wp option update openid_connect_generic_settings \"$serialized_empty_array\" --path={{ wordpress_docker_html_path }};"
|
||||
"serialized_empty_array=$(wp eval 'echo serialize(array());' --path={{ WORDPRESS_DOCKER_HTML_PATH }}); \
|
||||
wp option add openid_connect_generic_settings \"$serialized_empty_array\" --path={{ WORDPRESS_DOCKER_HTML_PATH }} \
|
||||
|| wp option update openid_connect_generic_settings \"$serialized_empty_array\" --path={{ WORDPRESS_DOCKER_HTML_PATH }};"
|
||||
args:
|
||||
chdir: "{{ docker_compose.directories.instance }}"
|
||||
failed_when: false
|
||||
@@ -20,6 +20,6 @@
|
||||
oidc_settings_json_b64: "{{ oidc_vars.oidc_settings | to_json | b64encode }}"
|
||||
command: >
|
||||
docker-compose exec -u www-data -T application bash -lc
|
||||
"wp eval \"update_option('openid_connect_generic_settings', json_decode(base64_decode('{{ oidc_settings_json_b64 }}'), true));\" --path={{ wordpress_docker_html_path }}"
|
||||
"wp eval \"update_option('openid_connect_generic_settings', json_decode(base64_decode('{{ oidc_settings_json_b64 }}'), true));\" --path={{ WORDPRESS_DOCKER_HTML_PATH }}"
|
||||
args:
|
||||
chdir: "{{ docker_compose.directories.instance }}"
|
||||
|
@@ -56,7 +56,7 @@
|
||||
command: >
|
||||
docker-compose exec -u www-data -T application
|
||||
wp plugin install wp-discourse --activate
|
||||
--path={{ wordpress_docker_html_path }}
|
||||
--path={{ WORDPRESS_DOCKER_HTML_PATH }}
|
||||
args:
|
||||
chdir: "{{ docker_compose.directories.instance }}"
|
||||
|
||||
@@ -89,6 +89,6 @@
|
||||
base64_decode('{{ option_json_b64 }}'),
|
||||
true
|
||||
)
|
||||
);\" --path={{ wordpress_docker_html_path }}"
|
||||
);\" --path={{ WORDPRESS_DOCKER_HTML_PATH }}"
|
||||
args:
|
||||
chdir: "{{ docker_compose.directories.instance }}"
|
@@ -1,4 +1,4 @@
|
||||
FROM {{ wordpress_image }}:{{ wordpress_version }}
|
||||
FROM {{ WORDPRESS_IMAGE }}:{{ WORDPRESS_VERSION }}
|
||||
|
||||
# Install msmtp and update system
|
||||
RUN apt-get update && \
|
||||
|
@@ -1,14 +1,14 @@
|
||||
{% include 'roles/docker-compose/templates/base.yml.j2' %}
|
||||
application:
|
||||
{% include 'roles/docker-container/templates/base.yml.j2' %}
|
||||
image: {{ wordpress_custom_image }}
|
||||
container_name: {{ wordpress_container }}
|
||||
image: {{ WORDPRESS_CUSTOM_IMAGE }}
|
||||
container_name: {{ WORDPRESS_CONTAINER }}
|
||||
build:
|
||||
context: .
|
||||
ports:
|
||||
- "127.0.0.1:{{ ports.localhost.http[application_id] }}:80"
|
||||
volumes:
|
||||
- data:{{ wordpress_docker_html_path }}
|
||||
- data:{{ WORDPRESS_DOCKER_HTML_PATH }}
|
||||
|
||||
{% include 'roles/docker-container/templates/healthcheck/msmtp_curl.yml.j2' %}
|
||||
{% include 'roles/docker-container/templates/depends_on/dmbs_excl.yml.j2' %}
|
||||
@@ -18,4 +18,4 @@
|
||||
|
||||
{% include 'roles/docker-compose/templates/volumes.yml.j2' %}
|
||||
data:
|
||||
name: "{{ wordpress_volume }}"
|
||||
name: "{{ WORDPRESS_VOLUME }}"
|
||||
|
@@ -1,7 +1,7 @@
|
||||
file_uploads = On
|
||||
memory_limit = {{ wordpress_max_upload_size }}
|
||||
upload_max_filesize = {{ wordpress_max_upload_size }}
|
||||
post_max_size = {{ wordpress_max_upload_size }}
|
||||
memory_limit = {{ WORDPRESS_MAX_UPLOAD_SIZE }}
|
||||
upload_max_filesize = {{ WORDPRESS_MAX_UPLOAD_SIZE }}
|
||||
post_max_size = {{ WORDPRESS_MAX_UPLOAD_SIZE }}
|
||||
max_execution_time = 300
|
||||
|
||||
; Use msmtp as the Mail Transfer Agent
|
||||
|
@@ -1,19 +1,19 @@
|
||||
# General
|
||||
application_id: "web-app-wordpress"
|
||||
database_type: "mariadb"
|
||||
host_msmtp_conf: "{{docker_compose.directories.config}}msmtprc.conf"
|
||||
|
||||
# WordPress Specific
|
||||
wordpress_max_upload_size: "{{ applications | get_app_conf(application_id, 'max_upload_size') }}"
|
||||
wordpress_custom_image: "wordpress_custom"
|
||||
wordpress_docker_html_path: "/var/www/html"
|
||||
wordpress_docker_conf_path: "{{ wordpress_config_path }}"
|
||||
wordpress_version: "{{ applications | get_app_conf(application_id, 'docker.services.wordpress.version', True) }}"
|
||||
wordpress_image: "{{ applications | get_app_conf(application_id, 'docker.services.wordpress.image', True) }}"
|
||||
wordpress_container: "{{ applications | get_app_conf(application_id, 'docker.services.wordpress.name', True) }}"
|
||||
wordpress_volume: "{{ applications | get_app_conf(application_id, 'docker.volumes.data', True) }}"
|
||||
wordpress_domains: "{{ applications | get_app_conf(application_id, 'server.domains.canonical', True) }}"
|
||||
wordpress_plugins: "{{ applications | get_app_conf(application_id, 'plugins', True) | dict2items }}"
|
||||
wordpress_user: "www-data"
|
||||
wordpress_config_file: "wp-config.php"
|
||||
wordpress_config_path: "{{ wordpress_docker_html_path }}/{{ wordpress_config_file }}"
|
||||
WORDPRESS_HOST_MSMTP_CONF: "{{ [ docker_compose.directories.config, 'msmtprc.conf'] | path_join }}"
|
||||
WORDPRESS_MAX_UPLOAD_SIZE: "{{ applications | get_app_conf(application_id, 'max_upload_size') }}"
|
||||
WORDPRESS_CUSTOM_IMAGE: "wordpress_custom"
|
||||
WORDPRESS_DOCKER_HTML_PATH: "/var/www/html"
|
||||
WORDPRESS_DOCKER_CONF_PATH: "{{ WORDPRESS_CONFIG_PATH }}"
|
||||
WORDPRESS_VERSION: "{{ applications | get_app_conf(application_id, 'docker.services.wordpress.version') }}"
|
||||
WORDPRESS_IMAGE: "{{ applications | get_app_conf(application_id, 'docker.services.wordpress.image') }}"
|
||||
WORDPRESS_CONTAINER: "{{ applications | get_app_conf(application_id, 'docker.services.wordpress.name') }}"
|
||||
WORDPRESS_VOLUME: "{{ applications | get_app_conf(application_id, 'docker.volumes.data') }}"
|
||||
WORDPRESS_DOMAINS: "{{ applications | get_app_conf(application_id, 'server.domains.canonical') }}"
|
||||
WORDPRESS_PLUGINS: "{{ applications | get_app_conf(application_id, 'plugins') | dict2items }}"
|
||||
WORDPRESS_USER: "www-data"
|
||||
WORDPRESS_CONFIG_FILE: "wp-config.php"
|
||||
WORDPRESS_CONFIG_PATH: "{{ [WORDPRESS_DOCKER_HTML_PATH, WORDPRESS_CONFIG_FILE] | path_join }}"
|
Reference in New Issue
Block a user