98 lines
2.6 KiB
YAML
98 lines
2.6 KiB
YAML
---
|
|
# tasks file for create cluster k8s via terraform
|
|
|
|
- name: Create directory {{ project_terraform }}
|
|
file:
|
|
path: "{{ project_backend }}"
|
|
state: directory
|
|
|
|
- name: Copy backend k8s yaml
|
|
template:
|
|
src: "{{ item }}.yaml.j2"
|
|
dest: "{{ project_backend }}/{{ item }}.yaml"
|
|
with_items: "{{ backend_yaml }}"
|
|
|
|
- name: Create a k8s namespace
|
|
kubernetes.core.k8s:
|
|
name: testing
|
|
api_version: v1
|
|
kind: Namespace
|
|
state: present
|
|
|
|
|
|
- name: Apply deployment
|
|
kubernetes.core.k8s:
|
|
src: "{{ project_backend }}/backend-deployment.yaml"
|
|
state: present
|
|
|
|
- name: Apply services
|
|
kubernetes.core.k8s:
|
|
src: "{{ project_backend }}/backend-service.yaml"
|
|
state: present
|
|
|
|
- name: Apply configmap
|
|
kubernetes.core.k8s:
|
|
src: "{{ project_backend }}/env-configmap.yaml"
|
|
state: present
|
|
|
|
|
|
- name: Apply secret
|
|
kubernetes.core.k8s:
|
|
src: "{{ project_backend }}/secret.yaml"
|
|
state: present
|
|
|
|
- name: En attente d'une adresse IP publique du cluster
|
|
ansible.builtin.pause:
|
|
minutes: 2
|
|
|
|
- name: Get IP Cluster
|
|
block:
|
|
- name: Fetch services
|
|
set_fact:
|
|
service: "{{ query('kubernetes.core.k8s', kind='Service', namespace='testing') }}"
|
|
register: result
|
|
|
|
- name: debug services
|
|
debug:
|
|
msg: "{{ result.ansible_facts.service[0].status.loadBalancer.ingress[0].ip }}"
|
|
|
|
- name: Test API Backend
|
|
ansible.builtin.uri:
|
|
url: "http://{{ result.ansible_facts.service[0].status.loadBalancer.ingress[0].ip }}:{{ port }}/api/hello"
|
|
status_code: 200
|
|
method: GET
|
|
tags: ["services", "dns"]
|
|
|
|
- name: Add DNS for IP Cluster
|
|
block:
|
|
- name: Copy script add or update DNS
|
|
template:
|
|
src: "dns_add_update.py.j2"
|
|
dest: "{{ project_backend }}/dns_add_update.py"
|
|
|
|
- name: Copy requierements python
|
|
copy:
|
|
src: "requierements.txt"
|
|
dest: "{{ project_backend }}"
|
|
|
|
- name: Pip install requierements
|
|
shell: "pip3.10 install -r {{ project_backend }}/requierements.txt"
|
|
|
|
- name: En attente de l'installation des packages
|
|
ansible.builtin.pause:
|
|
minutes: 2
|
|
|
|
- name: Add or update DNS
|
|
shell: "python3.10 {{ project_backend }}/dns_add_update.py --ip {{ result.ansible_facts.service[0].status.loadBalancer.ingress[0].ip }}"
|
|
register: result
|
|
|
|
- name: Display result script
|
|
debug:
|
|
msg: "{{ result }}"
|
|
|
|
- name: Test API Backend with DNS
|
|
ansible.builtin.uri:
|
|
url: "http://api.valczeryba.ovh:{{ port }}/api/hello"
|
|
status_code: 200
|
|
method: GET
|
|
tags: [ "dns" ] |