chore(coolify): refactored cooliy role
This commit is contained in:
@@ -2,50 +2,67 @@
|
||||
- name: Validate coolify_state parameter
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- coolify_state in ['present', 'absent', 'latest']
|
||||
msg: "coolify_state must be one of: present, absent, latest"
|
||||
- coolify_state in ['present', 'absent', 'latest', 'stopped']
|
||||
msg: "coolify_state must be one of: present, absent, latest, stopped"
|
||||
tags: always
|
||||
|
||||
- name: Check if Coolify is installed (compose file exists)
|
||||
ansible.builtin.stat:
|
||||
path: "{{ coolify_base_dir }}/source/{{ coolify_compose_files[0] }}"
|
||||
register: coolify_installed
|
||||
- name: Detect Coolify installation status
|
||||
ansible.builtin.include_tasks: detect.yaml
|
||||
tags: always
|
||||
|
||||
- name: Check Coolify container status
|
||||
community.docker.docker_container_info:
|
||||
name: "{{ item }}"
|
||||
loop: "{{ coolify_container_names }}"
|
||||
register: coolify_containers
|
||||
when: coolify_installed.stat.exists
|
||||
tags: always
|
||||
- name: Ensure Docker network exists
|
||||
become: true
|
||||
community.docker.docker_network:
|
||||
name: "{{ coolify_docker_network }}"
|
||||
driver: bridge
|
||||
attachable: true
|
||||
state: present
|
||||
tags: coolify, docker, installation
|
||||
|
||||
- name: Set Coolify health fact
|
||||
ansible.builtin.set_fact:
|
||||
coolify_healthy: "{{ coolify_containers.results | selectattr('container', 'defined') | selectattr('container.State.Health.Status', 'defined') | selectattr('container.State.Health.Status', 'equalto', 'healthy') | list | length == coolify_container_names | length }}"
|
||||
when: coolify_containers is defined and coolify_containers.results is defined
|
||||
tags: always
|
||||
|
||||
- name: Include deletion tasks if state is absent
|
||||
- name: Uninstall Coolify
|
||||
ansible.builtin.include_tasks: delete.yaml
|
||||
when: coolify_state == 'absent'
|
||||
tags: coolify, deletion
|
||||
|
||||
- name: Include installation tasks when desired and not installed
|
||||
- name: Install Coolify
|
||||
ansible.builtin.include_tasks: install.yaml
|
||||
when: (coolify_state in ['present','latest']) and not coolify_installed.stat.exists
|
||||
when:
|
||||
- coolify_state in ['present', 'latest']
|
||||
- not coolify_installed.stat.exists
|
||||
tags: coolify, installation
|
||||
|
||||
- name: Include update tasks when latest requested and already installed
|
||||
- name: Update Coolify
|
||||
ansible.builtin.include_tasks: update.yaml
|
||||
when: (coolify_state == 'latest') and coolify_installed.stat.exists
|
||||
when:
|
||||
- coolify_state == 'latest'
|
||||
- coolify_installed.stat.exists
|
||||
tags: coolify, update
|
||||
|
||||
- name: Show status when present and already installed
|
||||
- name: Ensure Configuration
|
||||
ansible.builtin.include_tasks: configure.yaml
|
||||
when:
|
||||
- coolify_state == 'present'
|
||||
- coolify_installed.stat.exists
|
||||
tags: coolify, configuration
|
||||
|
||||
- name: Ensure Started
|
||||
ansible.builtin.include_tasks: start.yaml
|
||||
when:
|
||||
- coolify_state == 'present'
|
||||
- coolify_installed.stat.exists
|
||||
tags: coolify, start
|
||||
|
||||
- name: Stop Coolify
|
||||
ansible.builtin.include_tasks: stop.yaml
|
||||
when:
|
||||
- coolify_state == 'stopped'
|
||||
- coolify_installed.stat.exists
|
||||
tags: coolify, stop
|
||||
|
||||
- name: Show status
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "Coolify is already installed and running"
|
||||
- "Containers healthy: {{ coolify_healthy | default('unknown') }}"
|
||||
- "Access at: http://{{ ansible_host }}:{{ coolify_http_port }}"
|
||||
when: (coolify_state == 'present') and coolify_installed.stat.exists | default(false)
|
||||
- "Coolify State: {{ coolify_state }}"
|
||||
- "URL: http://{{ ansible_host }}:{{ coolify_http_port }}"
|
||||
when: coolify_state in ['present', 'latest']
|
||||
tags: coolify, status
|
||||
|
||||
Reference in New Issue
Block a user