Update wordpress to use service role

This commit is contained in:
uumas
2024-07-28 01:20:10 +03:00
parent 5921c7d5db
commit a773666715
6 changed files with 98 additions and 12 deletions

View File

@@ -1,5 +1,7 @@
---
docker_service_name: wordpress
wordpress_tag: php8.1
docker_additional_services: []

View File

@@ -0,0 +1,25 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include wordpress"
ansible.builtin.include_role:
name: "wordpress"
vars:
docker_additional_services:
- memcached
- redis
wordpress_php_extensions:
- pdo_mysql
wordpress_additional_volumes:
- www
- log
database_passwords:
wordpress: molecule
docker_vhost_domains:
wordpress:
- localhost
admin_email: molecule@example.com
ports:
wordpress:
http: 28001

View File

@@ -0,0 +1,15 @@
---
dependency:
name: galaxy
driver:
name: podman
platforms:
- name: bullseye
image: git.uumas.fi/uumas/molecule-testbed:bullseye-docker
command: /lib/systemd/systemd
pre_build_image: true
privileged: true
provisioner:
name: ansible
verifier:
name: ansible

View File

@@ -0,0 +1,44 @@
---
# This is an example playbook to execute Ansible tests.
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Ensure https://localhost responds appropriately
ansible.builtin.uri:
url: https://localhost
validate_certs: false
return_content: true
register: get_localhost
- name: "Assert caddy responded on https://localhost"
ansible.builtin.assert:
that: "(get_localhost.server | split(', '))[0] == 'Caddy'"
- name: "Assert apache responded on https://localhost"
ansible.builtin.assert:
that: "(get_localhost.server | split(', '))[1].startswith('Apache')"
- name: Assert there was a redirect
ansible.builtin.assert:
that: "get_localhost.redirected == true"
- name: Get docker host info
community.docker.docker_host_info:
volumes: true
register: docker_host_out
- name: Assert all containers are running
ansible.builtin.assert:
that: docker_host_out.host_info.Containers == docker_host_out.host_info.ContainersRunning
msg: There should have been {{ docker_host_out.host_info.Containers }} containers running but there were {{ docker_host_out.host_info.ContainersRunning }}
- name: Assert correct number of containers were created
ansible.builtin.assert:
that: docker_host_out.host_info.Containers == 4
msg: There should have been 4 containers created but there were {{ docker_host_out.host_info.Containers }}
- name: Assert correct number of images were pulled
ansible.builtin.assert:
that: docker_host_out.host_info.Images == 6
msg: There should have been 4 images present but there were {{ docker_host_out.host_info.Images }}
- name: Assert no volumes were created
ansible.builtin.assert:
that: docker_host_out.volumes | length == 0
msg: There should have been no volumes present but there were {{ docker_host_out.volumes | length }}

View File

@@ -6,16 +6,16 @@
- name: Set docker service full name (required because docker_env uses it)
set_fact:
docker_service_name: "wordpress_{{ docker_service_suffix }}"
docker_service_name: "wordpress-{{ docker_service_suffix }}"
when: docker_service_suffix is defined
- name: Add memcached php extension to container
set_fact:
dockerfile: >
"{{ dockerfile +
['RUN apt-get update && \
apt-get install -y libmemcached-dev libssl-dev zlib1g-dev && \
pecl install memcached-3.2.0 && docker-php-ext-enable memcached'] }}"
{{ dockerfile +
['RUN apt-get update &&
apt-get install -y libmemcached-dev libssl-dev zlib1g-dev &&
pecl install memcached-3.2.0 && docker-php-ext-enable memcached'] }}
when: "'memcached' in docker_additional_services"
- name: Add pdo_mysql php extension to container
@@ -28,19 +28,19 @@
loop: "{{ wordpress_additional_volumes | default([]) }}"
- name: Wordpress container setup
include_role:
name: container
ansible.builtin.include_role:
name: service
vars:
docker_service: wordpress
docker_image: wordpress:{{ wordpress_tag }}
docker_image_http_port: 80
docker_database: mariadb
docker_volumes: "{{ wordpress_docker_volumes + wordpress_www_volume + wordpress_log_volume }}"
docker_mounts: "{{ wordpress_docker_mounts + wordpress_www_volume + wordpress_log_volume }}"
docker_volume_type: bind
docker_env:
WORDPRESS_DB_HOST: "{{ docker_service_name }}_db"
WORDPRESS_DB_NAME: "{{ docker_service_name }}"
WORDPRESS_DB_USER: "{{ docker_service_name }}"
WORDPRESS_DB_HOST: "{{ docker_service_name }}-db"
WORDPRESS_DB_NAME: "{{ docker_service_name | replace('-', '_') }}"
WORDPRESS_DB_USER: "{{ docker_service_name | replace('-', '_') }}"
WORDPRESS_DB_PASSWORD: "{{ database_passwords[docker_service_name] }}"
WORDPRESS_CONFIG_EXTRA: |
define('WP_SITEURL', 'https://{{ docker_vhost_domains[docker_service_name][0] }}');

View File

@@ -1,6 +1,6 @@
---
wordpress_docker_volumes:
wordpress_docker_mounts:
- name: html
path: /var/www/html
- template: php.ini