From 59fddd7fa91074461140cef4e10bd5a0605fc3de Mon Sep 17 00:00:00 2001 From: Olivier Navas Date: Wed, 20 Jul 2022 12:02:01 +0200 Subject: [PATCH] Commit initial --- README.md | 38 +++++++++++++++++++++++++++++++ defaults/main.yml | 0 handlers/main.yml | 5 ++++ tasks/main.yml | 14 ++++++++++++ templates/docker-compose.yml | 44 ++++++++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 tasks/main.yml create mode 100644 templates/docker-compose.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..841dbe6 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# Role : docker_wordpress + + +## Services fournis + +Installation d'une instance wordpress sur un serveur docker_host + +## Variables + +Fournir les variables suivantes. Par exemple : + +```yaml +docker_wordpress_fqdn: monsite.libretic.fr +docker_wordpress_data_dir: /data1 +docker_wordpress_service_id: monsite +docker_wordpress_image_version: 6.0.0-apache +docker_wordpress_db_name: wp +docker_wordpress_db_user: wp +docker_wordpress_db_password: mdp_bdd +``` + +| Option | Valeur par défaut | Description | +|--------------------------------|-------------------|-------------------------------------------------------------------------------------------| +| docker_wordpress_fqdn | | Nom de domaine, ou liste de noms de domaines, pour lequel le service wordpress répond | +| docker_wordpress_data_dir | | L'emplacement dans lequel se trouvent les volumes de donnees docker pour le service | +| docker_wordpress_service_id | | Le nom de service souhaité : conditionne le nommage des volumes et le routage par traefik | +| docker_wordpress_image_version | | Version de wordpress et de l'image docker | +| docker_wordpress_db_name | | Nom de la base de données | +| docker_wordpress_db_user | | Nom du user proprietaire de la base de donnees | +| docker_wordpress_db_password | | Mot de passe du user proprietaire de la base de donnees | + + + +## Poursuite de l'installation dans wordpress + +Après le premier lancement : +- créer le compte administrateur interne de wordpress depuis la page d'administration + diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..6dcba19 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,5 @@ +- name: docker-compose-up + shell: | + docker-compose up -d + args: + chdir: /opt/{{ docker_wordpress_service_id }}/ diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..cfcfaed --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,14 @@ +- name: docker directory + file: + path: /opt/{{ docker_wordpress_service_id }}/ + state: directory + +- name: prepare docker-compose.yml + template: + src: "{{ item }}" + dest: /opt/{{ docker_wordpress_service_id }}/ + with_items: + - docker-compose.yml + notify: docker-compose-up + + diff --git a/templates/docker-compose.yml b/templates/docker-compose.yml new file mode 100644 index 0000000..0b39d8f --- /dev/null +++ b/templates/docker-compose.yml @@ -0,0 +1,44 @@ +# {{ ansible_managed }} + +version: '3.1' + +services: + wordpress: + image: wordpress:{{ docker_wordpress_image_version }} + restart: always + environment: + WORDPRESS_DB_HOST: db + WORDPRESS_DB_USER: "{{ docker_wordpress_db_user }}" + WORDPRESS_DB_PASSWORD: "{{ docker_wordpress_db_password }}" + WORDPRESS_DB_NAME: "{{ docker_wordpress_db_name }}" + volumes: + - /data1/{{ docker_wordpress_service_id }}/wp_html:/var/www/html + labels: + - "traefik.enable=true" + - "traefik.docker.network=traefik" + - "traefik.http.routers.{{ docker_wordpress_service_id }}.entrypoints=web" + - "traefik.http.routers.{{ docker_wordpress_service_id }}.rule=Host(`{{ docker_wordpress_fqdn }}`)" + - "traefik.http.services.{{ docker_wordpress_service_id }}.loadbalancer.server.port=80" + networks: + - wordpress + - traefik + + db: + image: mariadb:10.8.2-rc-focal + restart: always + volumes: + - {{ docker_wordpress_data_dir }}/data1/{{ docker_wordpress_service_id }}/mysql:/var/lib/mysql + environment: + # genere un mdp root et l'affiche au demarrage sur stdout + MARIADB_RANDOM_ROOT_PASSWORD: "yes" + MARIADB_DATABASE: "{{ docker_wordpress_db_name }}" + MARIADB_USER: "{{ docker_wordpress_db_user }}" + MARIADB_PASSWORD: "{{ docker_wordpress_db_password }}" + networks: + - wordpress + +networks: + traefik: + external: true + wordpress: + internal: true