testroom/k8s.yaml

58 lines
1.7 KiB
YAML

---
- name: Deploy Kubernetes manifests from Gitea repository
hosts: localhost
connection: local
vars:
kube_config: "~/.kube/config"
repo_url: "https://gitea.jeekkaaaa.com/jeekkaaaa/testroom.git"
repo_version: "main" # Можно изменить на нужную ветку/тег
repo_dest: "/tmp/k8s-deploy"
namespace: "default" # Можно изменить на нужный namespace
tasks:
- name: Ensure required packages are installed
become: yes
apt:
name:
- git
- kubectl
state: present
when: ansible_os_family == 'Debian'
- name: Clone repository from Gitea
git:
repo: "{{ repo_url }}"
dest: "{{ repo_dest }}"
version: "{{ repo_version }}"
force: yes
register: clone_result
retries: 3
delay: 10
until: clone_result is succeeded
- name: Validate Kubernetes manifests
command: "kubectl apply --dry-run=client --validate=false -f {{ repo_dest }}/{{ item }}"
with_items:
- ngpod.yaml
- ngserv.yaml
register: validate_result
changed_when: false
- name: Deploy ngserv.yaml (Service)
k8s:
state: present
src: "{{ repo_dest }}/ngserv.yaml"
namespace: "{{ namespace }}"
- name: Deploy ngpod.yaml (Pod/Deployment)
k8s:
state: present
src: "{{ repo_dest }}/ngpod.yaml"
namespace: "{{ namespace }}"
- name: Verify deployment status
command: "kubectl get -f {{ repo_dest }}/ngpod.yaml -o jsonpath='{.status.phase}'"
register: deploy_status
until: deploy_status.stdout == "Running" or deploy_status.stdout == "Succeeded"
retries: 10
delay: 10