ansible rework

This commit is contained in:
Sergei Poljanski 2025-11-04 11:06:35 +02:00
commit eecff4345a
47 changed files with 1995 additions and 538 deletions

View file

@ -0,0 +1,81 @@
---
# Shared tasks for deploying Docker-based services
# This role provides a standardized pattern for service deployment
- name: Validate required variables
ansible.builtin.assert:
that:
- service_name is defined
- service_name | length > 0
- service_base_path is defined
- service_base_path | length > 0
fail_msg: "service_name and service_base_path are required variables"
success_msg: "Required variables validated for {{ service_name }}"
- name: Create base service directory
ansible.builtin.file:
path: "{{ service_base_path }}"
state: directory
mode: '0755'
owner: root
group: root
- name: Create service subdirectories
ansible.builtin.file:
path: "{{ service_base_path }}/{{ item.path }}"
state: directory
mode: "{{ item.mode | default('0755') }}"
owner: root
group: root
loop: "{{ service_directories }}"
when: service_directories | length > 0
- name: Deploy service template files
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ service_base_path }}/{{ item.dest }}"
mode: "{{ item.mode | default('0644') }}"
owner: root
group: root
loop: "{{ service_templates }}"
when: service_templates | length > 0
register: template_result
- name: Start service with Docker Compose
community.docker.docker_compose_v2:
project_src: "{{ service_base_path }}"
project_name: "{{ docker_compose_project_name }}"
files:
- "{{ docker_compose_file }}"
state: present
register: compose_result
- name: Wait before health check
ansible.builtin.pause:
seconds: "{{ health_check_delay }}"
when: health_check_enabled and (health_check_url != "" or health_check_port != "")
- name: Wait for service HTTP endpoint
ansible.builtin.uri:
url: "{{ health_check_url }}"
status_code: [200, 301, 302, 401, 404] # Accept various codes (service-dependent)
timeout: 5
register: health_result
until: health_result is not failed
retries: "{{ health_check_retries }}"
delay: "{{ health_check_retry_delay }}"
when: health_check_enabled and health_check_url != ""
failed_when: false
- name: Wait for service port
ansible.builtin.wait_for:
host: "{{ health_check_host }}"
port: "{{ health_check_port }}"
delay: 0
timeout: "{{ health_check_retries * health_check_retry_delay }}"
state: started
when: health_check_enabled and health_check_port != ""
- name: Display deployment status
ansible.builtin.debug:
msg: "{{ service_name }} deployment completed successfully"