From 78eb056e091e16de246b657688d95b39d59fb7bc Mon Sep 17 00:00:00 2001 From: William Date: Fri, 1 Jul 2022 23:14:33 +0200 Subject: [PATCH] =?UTF-8?q?Playbook=20de=20cr=C3=A9ation=20d'une=20bdd.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- README.md | 40 +++++++++++++++++++++++++++++++++------- playbooks/db-create.yml | 20 ++++++++++++++++++++ 3 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 playbooks/db-create.yml diff --git a/.gitignore b/.gitignore index aa2c66c..064317d 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /playbook.retry /hosts.ini -/vars.json +/*.json diff --git a/README.md b/README.md index b640fe6..fb4fb68 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,21 @@ This playbook installs app from repository and bind Traefik on defined host. -## Usage +## Manage app -Copy then change values of hosts example file : +Available playbooks: + ++ app-install ++ app-start ++ app-stop + +Start by copy then change values of hosts example file : ```bash $ cp hosts.example.ini hosts.ini ``` -Then create a file `vars.json` vars who contain : +Then create a file `vars.json` who contain : ```json { @@ -35,8 +41,28 @@ Then run a playbook: $ ansible-playbook -i hosts.ini -e @vars.json playbooks/app-install.yml ``` -## Available playbooks: +## Manage database -+ app-install -+ app-start -+ app-stop +Available playbooks: + ++ db-create + +First create a file `dbvars.json` who contain : + +```json +{ + "container_name": "myappdb", + "envvars": { + "MYSQL_ROOT_PASSWORD": "superpassword", + "MYSQL_DATABASE": "myappdb", + "MYSQL_USER": "user", + "MYSQL_PASSWORD": "password" + } +} +``` + +Then run a playbook: + +```bash +$ ansible-playbook -i hosts.ini -e @dbvars.json playbooks/db-create.yml +``` diff --git a/playbooks/db-create.yml b/playbooks/db-create.yml new file mode 100644 index 0000000..075db1e --- /dev/null +++ b/playbooks/db-create.yml @@ -0,0 +1,20 @@ +--- +- name: Create mysql database + hosts: webservers + become: yes + + tasks: + - name: Create database volume + community.docker.docker_volume: + name: "{{ container_name }}" + + - name: Create database container + community.docker.docker_container: + image: mysql:8.0 + name: "{{ container_name }}" + restart_policy: unless-stopped + networks: + - name: web + volumes: + - "{{ container_name }}:/var/lib/mysql" + env: "{{ envvars }}"