diff --git a/server/.travis.yml b/db/.travis.yml similarity index 100% rename from server/.travis.yml rename to db/.travis.yml diff --git a/server/README.md b/db/README.md similarity index 100% rename from server/README.md rename to db/README.md diff --git a/server/defaults/main.yml b/db/defaults/main.yml similarity index 100% rename from server/defaults/main.yml rename to db/defaults/main.yml diff --git a/db/files/docker-compose-server.yml b/db/files/docker-compose-server.yml new file mode 100644 index 0000000..a45804c --- /dev/null +++ b/db/files/docker-compose-server.yml @@ -0,0 +1,30 @@ +version: "3.3" +services: + + db: + image: postgres + volumes: + - app-db-data:/var/lib/postgresql/data/pgdata + env_file: + - .env + environment: + - PGDATA=/var/lib/postgresql/data/pgdata + ports: + - "54321:5432" + + redis: + image: redis/redis-stack-server:latest + ports: + - "63791:6379" + + liquibase: + build: + context: ./covas-liquibase + dockerfile: Dockerfile + depends_on: + - db + command: + - "update" + +volumes: + app-db-data: diff --git a/server/handlers/main.yml b/db/handlers/main.yml similarity index 100% rename from server/handlers/main.yml rename to db/handlers/main.yml diff --git a/server/meta/main.yml b/db/meta/main.yml similarity index 100% rename from server/meta/main.yml rename to db/meta/main.yml diff --git a/db/tasks/deploy-db.yml b/db/tasks/deploy-db.yml new file mode 100644 index 0000000..51f9290 --- /dev/null +++ b/db/tasks/deploy-db.yml @@ -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 \ No newline at end of file diff --git a/db/tasks/main.yml b/db/tasks/main.yml new file mode 100644 index 0000000..a3a64be --- /dev/null +++ b/db/tasks/main.yml @@ -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"] \ No newline at end of file diff --git a/db/tasks/remove-db.yml b/db/tasks/remove-db.yml new file mode 100644 index 0000000..050d293 --- /dev/null +++ b/db/tasks/remove-db.yml @@ -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 \ No newline at end of file diff --git a/db/tasks/start-db.yml b/db/tasks/start-db.yml new file mode 100644 index 0000000..d7b6a07 --- /dev/null +++ b/db/tasks/start-db.yml @@ -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 \ No newline at end of file diff --git a/db/tasks/stop-db.yml b/db/tasks/stop-db.yml new file mode 100644 index 0000000..c78bd95 --- /dev/null +++ b/db/tasks/stop-db.yml @@ -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 diff --git a/db/templates/env.j2 b/db/templates/env.j2 new file mode 100644 index 0000000..f90d46b --- /dev/null +++ b/db/templates/env.j2 @@ -0,0 +1,3 @@ +POSTGRES_PASSWORD={{ postgres_password }} +POSTGRES_USER={{ postgres_user }} +POSTGRES_DB={{ postgres_db }} \ No newline at end of file diff --git a/server/vars/main.yml b/db/vars/main.yml similarity index 100% rename from server/vars/main.yml rename to db/vars/main.yml diff --git a/hosts b/hosts deleted file mode 100644 index e69de29..0000000 diff --git a/inventory/all b/inventory/all deleted file mode 100644 index e69de29..0000000 diff --git a/inventory/group_vars/db b/inventory/group_vars/db new file mode 100644 index 0000000..a744227 --- /dev/null +++ b/inventory/group_vars/db @@ -0,0 +1 @@ +postgres_db: toto \ No newline at end of file diff --git a/inventory/group_vars/db_vault b/inventory/group_vars/db_vault new file mode 100644 index 0000000..db089f3 --- /dev/null +++ b/inventory/group_vars/db_vault @@ -0,0 +1,10 @@ +$ANSIBLE_VAULT;1.1;AES256 +35323139356565316333376432336436666566666631363635366235316435313536373765383234 +6664623264396635643636663865626130616135326230610a373064656264323233663563623930 +38373762363331663632343036336139663833616638653361363535643239643166363435613764 +3864363664303836380a363739653638623639663262356532656262393862323164656531393531 +35663166376632663734356666306433383363386236613330663536326432306561653665356533 +64396538376432336532343366393938363963656432353638346165313836373136343433623435 +65626138633637653631386663386462623633656434363761623366626565396362663864613166 +33346136386532636132613532626133376534326339646161356461346434626335376661656534 +32343936616335376563363131643938333833376231663862333961383566666137 diff --git a/inventory/hosts b/inventory/hosts new file mode 100644 index 0000000..6710a9f --- /dev/null +++ b/inventory/hosts @@ -0,0 +1,7 @@ +vps ansible_connection=ssh ansible_host=51.222.107.37 ansible_port=2424 ansible_user=valentin + +[db] +vps + +[db_vault:children] +db \ No newline at end of file diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..2aa7a66 --- /dev/null +++ b/main.tf @@ -0,0 +1,43 @@ +terraform { + required_providers { + scaleway = { + source = "scaleway/scaleway" + } + } + required_version = ">= 0.13" +} + +resource "scaleway_k8s_cluster" "terraform-test" { + name = "terraform-test" + version = "1.24.3" + cni = "cilium" + project_id = "81af2696-6120-4f45-baf3-d17fb0525824" + region = "fr-par" +} + + resource "scaleway_k8s_pool" "john" { + cluster_id = scaleway_k8s_cluster.terraform-test.id + name = "john" + node_type = "DEV1-M" + size = 1 + } + + resource "null_resource" "kubeconfig" { + depends_on = [scaleway_k8s_pool.john] # at least one pool here + triggers = { + host = scaleway_k8s_cluster.terraform-test.kubeconfig[0].host + token = scaleway_k8s_cluster.terraform-test.kubeconfig[0].token + cluster_ca_certificate = scaleway_k8s_cluster.terraform-test.kubeconfig[0].cluster_ca_certificate + } +} + + +provider "kubernetes" { + load_config_file = "false" + + host = null_resource.kubeconfig.triggers.host + token = null_resource.kubeconfig.triggers.token + cluster_ca_certificate = base64decode( + null_resource.kubeconfig.triggers.cluster_ca_certificate + ) +} \ No newline at end of file diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..9d6f5cb --- /dev/null +++ b/playbook.yml @@ -0,0 +1,5 @@ +--- +- hosts: db + remote_user: valentin + roles: + - db \ No newline at end of file diff --git a/server/tasks/main.yml b/server/tasks/main.yml deleted file mode 100644 index c33f790..0000000 --- a/server/tasks/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# tasks file for server diff --git a/test.yml b/test.yml deleted file mode 100644 index fa17688..0000000 --- a/test.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- hosts: localhost - remote_user: root - roles: - - server