re-organizing playbook deploy-db

This commit is contained in:
2022-10-08 18:15:53 +02:00
parent fd1d6b6261
commit a844e10970
22 changed files with 116 additions and 215 deletions

34
db/tasks/deploy-db.yml Normal file
View File

@@ -0,0 +1,34 @@
# deploy db postgresql, liquibase and redis
- name: git archive local
local_action:
module: git
repo: "https://{{ git_username | urlencode }}:{{ git_password | urlencode }}@git.valczeryba.ovh/v4l3n71n/covas-liquibase.git"
dest: "/home/valentin/src/"
archive: "/tmp/covas-liquibase.tar.gz"
force: yes
update: yes
run_once: True
- name: Create directory
file:
path: "/home/valentin/{{ item }}"
state: directory
with_items:
- db
- db/covas-liquibase
- name: Extract covas liquibase
unarchive:
src: "/tmp/covas-liquibase.tar.gz"
dest: "/home/valentin/db/covas-liquibase"
- name: Template env file
template:
src: env.j2
dest: /home/valentin/db/.env
- name: Copy docker compose server file
copy:
src: docker-compose-server.yml
dest: /home/valentin/db/docker-compose.yml

23
db/tasks/main.yml Normal file
View File

@@ -0,0 +1,23 @@
---
# tasks file for server
# include task db
- name: Deploy database postgresql and redis
ansible.builtin.import_tasks: deploy-db.yml
tags: ["start-with-deploy", "deploy"]
- name: Start db postgresql and redis
ansible.builtin.import_tasks: start-db.yml
tags: ["start-with-deploy", "start"]
- name: stop db postgresql and redis
ansible.builtin.import_tasks: stop-db.yml
tags: ["destroy", "stop"]
- name: Remove db
ansible.builtin.import_tasks: remove-db.yml
tags: ["destroy"]

18
db/tasks/remove-db.yml Normal file
View File

@@ -0,0 +1,18 @@
# remove db
- name: Stopping existing service
community.docker.docker_compose:
project_src: /home/valentin/db
state: absent
remove_volumes: yes
remove_images: local
register: output
- name: Debug output
debug:
var: output
- name: Remove project covas db
file:
path: /home/valentin/db
state: absent

34
db/tasks/start-db.yml Normal file
View File

@@ -0,0 +1,34 @@
# start services db
- name: Stopping existing service
community.docker.docker_compose:
project_src: /home/valentin/db
- name: Starting service
community.docker.docker_compose:
project_src: /home/valentin/db
register: output
- name: debug output
debug:
var: output
- name: Allow port postgresql
ansible.builtin.iptables:
chain: INPUT
protocol: tcp
destination_port: 54321
jump: ACCEPT
state: present
become: yes
become_method: sudo
- name: Allow port redis
ansible.builtin.iptables:
chain: INPUT
protocol: tcp
destination_port: 63791
jump: ACCEPT
state: present
become: yes
become_method: sudo

34
db/tasks/stop-db.yml Normal file
View File

@@ -0,0 +1,34 @@
# stop services db and redis
- name: Disallow port postgresql
ansible.builtin.iptables:
chain: INPUT
protocol: tcp
destination_port: 54321
jump: ACCEPT
state: absent
become: yes
become_method: sudo
- name: Disallow port redis
ansible.builtin.iptables:
chain: INPUT
protocol: tcp
destination_port: 63791
jump: ACCEPT
state: absent
become: yes
become_method: sudo
- name: Stopping existing service
community.docker.docker_compose:
project_src: /home/valentin/db
state: present
stopped: yes
register: output
- name: Debug output
debug:
var: output