77 lines
2 KiB
YAML
77 lines
2 KiB
YAML
---
|
|
- name: Get MySQL Service Info
|
|
kubernetes.core.k8s_info:
|
|
api_version: v1
|
|
kind: Service
|
|
name: mysql-service
|
|
namespace: default
|
|
register: mysql_service_info
|
|
|
|
- name: Extract ClusterIP from MySQL service
|
|
set_fact:
|
|
cluster_ip: "{{ mysql_service_info.resources[0].spec.clusterIP }}"
|
|
|
|
- name: Create ConfigMap for laravelio
|
|
kubernetes.core.k8s:
|
|
name: laravelio-config
|
|
namespace: default
|
|
definition:
|
|
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: laravelio-config
|
|
data:
|
|
DB_HOST: "{{ cluster_ip }}"
|
|
DB_DATABASE: laravelio
|
|
DB_USERNAME: laraveliouser
|
|
DB_PASSWORD: "123456"
|
|
|
|
- name: Wait for MySQL to be Running
|
|
kubernetes.core.k8s_info:
|
|
namespace: default
|
|
kind: Pod
|
|
label_selectors:
|
|
- "app=mysql"
|
|
register: mysql_pod_info
|
|
until: mysql_pod_info.resources[0].status.phase == "Running"
|
|
retries: 60
|
|
delay: 5
|
|
|
|
- name: Create laravelio Deployment
|
|
kubernetes.core.k8s:
|
|
namespace: default
|
|
state: present
|
|
src: roles/laravelio_deploy/templates/laravelio-deployment.yml
|
|
wait: yes
|
|
|
|
- name: Create laravelio Service
|
|
kubernetes.core.k8s:
|
|
namespace: default
|
|
state: present
|
|
src: roles/laravelio_deploy/templates/laravelio-service.yml
|
|
wait: yes
|
|
|
|
# Seed database section
|
|
|
|
- name: Get laravelio pod name
|
|
kubernetes.core.k8s_info:
|
|
namespace: default
|
|
kind: Pod
|
|
label_selectors:
|
|
- "app=laravelio"
|
|
register: laravelio_pod_info
|
|
when: seed_database is defined and seed_database == "true"
|
|
|
|
- name: Extract laravelio pod name
|
|
set_fact:
|
|
laravelio_pod_name: "{{ laravelio_pod_info.resources[0].metadata.name }}"
|
|
|
|
|
|
- name: Migrate database
|
|
command: "kubectl exec -t {{ laravelio_pod_name }} -- php artisan migrate"
|
|
when: seed_database is defined and seed_database == "true"
|
|
|
|
|
|
- name: Seed database
|
|
command: "kubectl exec -t {{ laravelio_pod_name }} -- php artisan db:seed"
|
|
when: seed_database is defined and seed_database == "true"
|