add roles build WIP

This commit is contained in:
2022-10-15 22:06:06 +02:00
parent 44dce58617
commit db8491f577
13 changed files with 261 additions and 0 deletions

31
build/tasks/deploy.yml Normal file
View File

@@ -0,0 +1,31 @@
# 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/{{ project_name }}.git"
dest: "/home/valentin/src/"
archive: "/tmp/{{ project_name }}.tar.gz"
force: yes
update: yes
when: "project_name is defined"
- name: Create directory
file:
path: "{{ home_dir }}/{{ project_name }}"
state: directory
when: "project_name is defined"
- name: Extract covas liquibase
unarchive:
src: "/tmp/{{ project_name }}.tar.gz"
dest: "{{ home_dir }}/{{ project_name }}"
when: "project_name is defined"
- name: Template env file
template:
src: "{{ project_env }}"
dest: "{{ home_dir }}/.env"
when: "project_env is defined"

19
build/tasks/main.yml Normal file
View File

@@ -0,0 +1,19 @@
---
# tasks file for server
- name: Deploy services
ansible.builtin.import_tasks: deploy.yml
tags: ["deploy", "create"]
- name: Start services
ansible.builtin.import_tasks: start.yml
tags: ["deploy", "start"]
- name: stop services
ansible.builtin.import_tasks: stop.yml
tags: ["destroy", "stop"]
- name: Remove services
ansible.builtin.import_tasks: remove.yml
tags: ["destroy"]

18
build/tasks/remove.yml Normal file
View File

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

29
build/tasks/start.yml Normal file
View File

@@ -0,0 +1,29 @@
# start services db
- name: Stopping existing service
community.docker.docker_compose:
project_src: "{{ project_src }}"
state: absent
- name: Starting service
community.docker.docker_compose:
project_src: "{{ project_src }}"
register: output
- name: debug output
debug:
var: output
- name: "Allow port {{ item }}"
ansible.builtin.iptables:
chain: INPUT
protocol: tcp
destination_port: "{{ item }}"
jump: ACCEPT
state: present
vars:
ansible_become: yes
ansible_become_method: sudo
ansible_become_password: "{{ sudo_password }}"
with_items: "{{ ports_tcp }}"

28
build/tasks/stop.yml Normal file
View File

@@ -0,0 +1,28 @@
# stop services db and redis
- name: Disallow port {{ item }}
ansible.builtin.iptables:
chain: INPUT
protocol: tcp
destination_port: "{{ item }}"
jump: ACCEPT
state: absent
vars:
ansible_become: yes
ansible_become_method: sudo
ansible_become_password: "{{ sudo_password }}"
with_items: "{{ ports_tcp }}"
- name: Stopping existing service
community.docker.docker_compose:
project_src: "{{ project_src }}"
state: present
stopped: yes
register: output
- name: Debug output
debug:
var: output