2022-12-10 15:24:35 +01:00
|
|
|
---
|
|
|
|
# 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:
|
2022-12-10 20:14:13 +01:00
|
|
|
src: "{{ item }}.yaml.j2"
|
2022-12-10 15:24:35 +01:00
|
|
|
dest: "{{ project_backend }}/{{ item }}.yaml"
|
|
|
|
with_items: "{{ backend_yaml }}"
|
|
|
|
|
2022-12-10 22:10:13 +01:00
|
|
|
- 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
|
|
|
|
|
2022-12-10 23:05:52 +01:00
|
|
|
- name: Pause for 2 minutes to build app cache
|
|
|
|
ansible.builtin.pause:
|
|
|
|
minutes: 2
|
2022-12-10 22:10:13 +01:00
|
|
|
|
2022-12-10 23:05:52 +01:00
|
|
|
- name: Fetch services
|
|
|
|
set_fact:
|
|
|
|
service: "{{ query('kubernetes.core.k8s', kind='Service', namespace='testing', label_selector='io.kompose.service=backend') }}"
|
|
|
|
register: result
|
|
|
|
tags: [ "services"]
|
2022-12-10 22:10:13 +01:00
|
|
|
|
2022-12-10 23:05:52 +01:00
|
|
|
- name: debug services
|
|
|
|
debug:
|
|
|
|
msg: "{{ result.ansible_facts.service[0].status.loadBalancer.ingress[0].ip }}"
|
|
|
|
tags: [ "services"]
|
2022-12-10 22:10:13 +01:00
|
|
|
|
2022-12-10 23:05:52 +01:00
|
|
|
- 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" ]
|
2022-12-10 22:10:13 +01:00
|
|
|
|
2022-12-10 15:24:35 +01:00
|
|
|
|