chore(coolify): refactored cooliy role
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
---
|
||||
coolify_state: present # latest | present | absent
|
||||
coolify_state: present # latest | present | absent
|
||||
coolify_remove_data_on_absent: false
|
||||
coolify_base_dir: /data/coolify
|
||||
|
||||
@@ -17,3 +17,22 @@ coolify_container_names:
|
||||
- coolify-db
|
||||
- coolify-redis
|
||||
- coolify-realtime
|
||||
|
||||
coolify_app_id: ""
|
||||
coolify_app_name: "Coolify"
|
||||
coolify_app_key: ""
|
||||
|
||||
coolify_db_username: "coolify"
|
||||
coolify_db_password: ""
|
||||
|
||||
coolify_redis_password: ""
|
||||
|
||||
coolify_pusher_app_id: ""
|
||||
coolify_pusher_app_key: ""
|
||||
coolify_pusher_app_secret: ""
|
||||
|
||||
coolify_root_username: ""
|
||||
coolify_root_user_email: ""
|
||||
coolify_root_user_password: ""
|
||||
|
||||
coolify_registry_url: "ghcr.io"
|
||||
|
||||
@@ -7,16 +7,10 @@
|
||||
ignore_errors: true
|
||||
tags: coolify, deletion, pre-check
|
||||
|
||||
- name: Stop and remove Coolify services (compose down)
|
||||
become: true
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: "{{ coolify_base_dir }}/source"
|
||||
files: "{{ coolify_compose_files }}"
|
||||
state: absent
|
||||
remove_orphans: true
|
||||
remove_volumes: false
|
||||
- name: Stop Coolify services
|
||||
ansible.builtin.include_tasks: stop.yaml
|
||||
ignore_errors: true
|
||||
tags: coolify, docker, deletion
|
||||
tags: coolify, deletion, stop
|
||||
|
||||
- name: Force remove any remaining Coolify containers
|
||||
community.docker.docker_container:
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
state: directory
|
||||
owner: "{{ coolify_owner }}"
|
||||
group: "{{ coolify_group }}"
|
||||
mode: '0750'
|
||||
mode: "0750"
|
||||
loop:
|
||||
- "{{ coolify_base_dir }}/source"
|
||||
- "{{ coolify_base_dir }}/ssh/keys"
|
||||
@@ -39,68 +39,31 @@
|
||||
ansible.builtin.get_url:
|
||||
url: "https://cdn.coollabs.io/coolify/{{ item.file }}"
|
||||
dest: "{{ coolify_base_dir }}/source/{{ item.dest }}"
|
||||
mode: '0644'
|
||||
mode: "0644"
|
||||
owner: "{{ coolify_owner }}"
|
||||
group: "{{ coolify_group }}"
|
||||
loop:
|
||||
- { file: "docker-compose.yml", dest: "docker-compose.yml" }
|
||||
- { file: "docker-compose.prod.yml", dest: "docker-compose.prod.yml" }
|
||||
- { file: "upgrade.sh", dest: "upgrade.sh" }
|
||||
tags: coolify, files, installation
|
||||
|
||||
- name: Ensure .env exists from template (only when missing)
|
||||
ansible.builtin.stat:
|
||||
path: "{{ coolify_base_dir }}/source/.env"
|
||||
register: env_file_check
|
||||
tags: coolify, files, installation
|
||||
|
||||
- name: Create .env from template when missing
|
||||
ansible.builtin.template:
|
||||
src: "templates/.env.production.j2"
|
||||
dest: "{{ coolify_base_dir }}/source/.env"
|
||||
mode: '0640'
|
||||
when: not env_file_check.stat.exists
|
||||
tags: coolify, files, installation
|
||||
- name: Configure Coolify environment
|
||||
ansible.builtin.include_tasks: configure.yaml
|
||||
tags: coolify, configuration, installation
|
||||
|
||||
- name: Ensure correct ownership and permissions recursively
|
||||
ansible.builtin.file:
|
||||
path: "{{ coolify_base_dir }}"
|
||||
owner: "{{ coolify_owner }}"
|
||||
group: "{{ coolify_group }}"
|
||||
mode: '0750'
|
||||
mode: "0750"
|
||||
recurse: true
|
||||
tags: coolify, permissions, installation
|
||||
|
||||
- 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: Start Coolify services
|
||||
become: true
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: "{{ coolify_base_dir }}/source"
|
||||
files: "{{ coolify_compose_files }}"
|
||||
pull: always
|
||||
state: present
|
||||
wait: true
|
||||
wait_timeout: 300
|
||||
tags: coolify, docker, installation
|
||||
|
||||
- name: Wait for Coolify HTTP to respond
|
||||
ansible.builtin.uri:
|
||||
url: "http://localhost:{{ coolify_http_port }}"
|
||||
method: GET
|
||||
status_code: 200
|
||||
timeout: 30
|
||||
body_format: json
|
||||
register: coolify_health
|
||||
until: coolify_health.status == 200
|
||||
retries: 10
|
||||
delay: 10
|
||||
tags: coolify, health, installation
|
||||
- name: Start Coolify
|
||||
ansible.builtin.include_tasks: start.yaml
|
||||
tags: coolify, start, installation
|
||||
|
||||
- name: Show installed message
|
||||
ansible.builtin.debug:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
---
|
||||
- name: Update Coolify services with recreate
|
||||
- name: Update Coolify configuration files
|
||||
ansible.builtin.get_url:
|
||||
url: "https://cdn.coollabs.io/coolify/{{ item.file }}"
|
||||
dest: "{{ coolify_base_dir }}/source/{{ item.dest }}"
|
||||
mode: "0644"
|
||||
owner: "{{ coolify_owner }}"
|
||||
group: "{{ coolify_group }}"
|
||||
loop:
|
||||
- { file: "docker-compose.yml", dest: "docker-compose.yml" }
|
||||
- { file: "docker-compose.prod.yml", dest: "docker-compose.prod.yml" }
|
||||
- { file: "upgrade.sh", dest: "upgrade.sh" }
|
||||
tags: coolify, files, update
|
||||
|
||||
- name: Ensure Coolify environment configuration exists
|
||||
ansible.builtin.include_tasks: configure.yaml
|
||||
tags: coolify, configuration, update
|
||||
|
||||
- name: Update Coolify services (pull and recreate)
|
||||
become: true
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: "{{ coolify_base_dir }}/source"
|
||||
files: "{{ coolify_compose_files }}"
|
||||
@@ -8,7 +26,7 @@
|
||||
recreate: always
|
||||
wait: true
|
||||
wait_timeout: 300
|
||||
tags: coolify, update
|
||||
tags: coolify, docker, update
|
||||
|
||||
- name: Wait for Coolify HTTP to respond after update
|
||||
ansible.builtin.uri:
|
||||
@@ -19,14 +37,14 @@
|
||||
body_format: json
|
||||
register: coolify_health_after_update
|
||||
until: coolify_health_after_update.status == 200
|
||||
retries: 10
|
||||
delay: 10
|
||||
retries: 20
|
||||
delay: 15
|
||||
tags: coolify, update, health
|
||||
|
||||
- name: Show update success message
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "Coolify updated successfully to latest version"
|
||||
- "All containers are healthy and responding"
|
||||
- "Services have been recreated with latest images and config"
|
||||
- "Access at: http://{{ ansible_host }}:{{ coolify_http_port }}"
|
||||
tags: coolify, update
|
||||
|
||||
Reference in New Issue
Block a user