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_remove_data_on_absent: false
|
||||||
coolify_base_dir: /data/coolify
|
coolify_base_dir: /data/coolify
|
||||||
|
|
||||||
@@ -17,3 +17,22 @@ coolify_container_names:
|
|||||||
- coolify-db
|
- coolify-db
|
||||||
- coolify-redis
|
- coolify-redis
|
||||||
- coolify-realtime
|
- 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
|
ignore_errors: true
|
||||||
tags: coolify, deletion, pre-check
|
tags: coolify, deletion, pre-check
|
||||||
|
|
||||||
- name: Stop and remove Coolify services (compose down)
|
- name: Stop Coolify services
|
||||||
become: true
|
ansible.builtin.include_tasks: stop.yaml
|
||||||
community.docker.docker_compose_v2:
|
|
||||||
project_src: "{{ coolify_base_dir }}/source"
|
|
||||||
files: "{{ coolify_compose_files }}"
|
|
||||||
state: absent
|
|
||||||
remove_orphans: true
|
|
||||||
remove_volumes: false
|
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
tags: coolify, docker, deletion
|
tags: coolify, deletion, stop
|
||||||
|
|
||||||
- name: Force remove any remaining Coolify containers
|
- name: Force remove any remaining Coolify containers
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
state: directory
|
state: directory
|
||||||
owner: "{{ coolify_owner }}"
|
owner: "{{ coolify_owner }}"
|
||||||
group: "{{ coolify_group }}"
|
group: "{{ coolify_group }}"
|
||||||
mode: '0750'
|
mode: "0750"
|
||||||
loop:
|
loop:
|
||||||
- "{{ coolify_base_dir }}/source"
|
- "{{ coolify_base_dir }}/source"
|
||||||
- "{{ coolify_base_dir }}/ssh/keys"
|
- "{{ coolify_base_dir }}/ssh/keys"
|
||||||
@@ -39,68 +39,31 @@
|
|||||||
ansible.builtin.get_url:
|
ansible.builtin.get_url:
|
||||||
url: "https://cdn.coollabs.io/coolify/{{ item.file }}"
|
url: "https://cdn.coollabs.io/coolify/{{ item.file }}"
|
||||||
dest: "{{ coolify_base_dir }}/source/{{ item.dest }}"
|
dest: "{{ coolify_base_dir }}/source/{{ item.dest }}"
|
||||||
mode: '0644'
|
mode: "0644"
|
||||||
|
owner: "{{ coolify_owner }}"
|
||||||
|
group: "{{ coolify_group }}"
|
||||||
loop:
|
loop:
|
||||||
- { file: "docker-compose.yml", dest: "docker-compose.yml" }
|
- { file: "docker-compose.yml", dest: "docker-compose.yml" }
|
||||||
- { file: "docker-compose.prod.yml", dest: "docker-compose.prod.yml" }
|
- { file: "docker-compose.prod.yml", dest: "docker-compose.prod.yml" }
|
||||||
- { file: "upgrade.sh", dest: "upgrade.sh" }
|
- { file: "upgrade.sh", dest: "upgrade.sh" }
|
||||||
tags: coolify, files, installation
|
tags: coolify, files, installation
|
||||||
|
|
||||||
- name: Ensure .env exists from template (only when missing)
|
- name: Configure Coolify environment
|
||||||
ansible.builtin.stat:
|
ansible.builtin.include_tasks: configure.yaml
|
||||||
path: "{{ coolify_base_dir }}/source/.env"
|
tags: coolify, configuration, installation
|
||||||
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: Ensure correct ownership and permissions recursively
|
- name: Ensure correct ownership and permissions recursively
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ coolify_base_dir }}"
|
path: "{{ coolify_base_dir }}"
|
||||||
owner: "{{ coolify_owner }}"
|
owner: "{{ coolify_owner }}"
|
||||||
group: "{{ coolify_group }}"
|
group: "{{ coolify_group }}"
|
||||||
mode: '0750'
|
mode: "0750"
|
||||||
recurse: true
|
recurse: true
|
||||||
tags: coolify, permissions, installation
|
tags: coolify, permissions, installation
|
||||||
|
|
||||||
- name: Ensure Docker network exists
|
- name: Start Coolify
|
||||||
become: true
|
ansible.builtin.include_tasks: start.yaml
|
||||||
community.docker.docker_network:
|
tags: coolify, start, installation
|
||||||
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: Show installed message
|
- name: Show installed message
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
|
|||||||
@@ -2,50 +2,67 @@
|
|||||||
- name: Validate coolify_state parameter
|
- name: Validate coolify_state parameter
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- coolify_state in ['present', 'absent', 'latest']
|
- coolify_state in ['present', 'absent', 'latest', 'stopped']
|
||||||
msg: "coolify_state must be one of: present, absent, latest"
|
msg: "coolify_state must be one of: present, absent, latest, stopped"
|
||||||
tags: always
|
tags: always
|
||||||
|
|
||||||
- name: Check if Coolify is installed (compose file exists)
|
- name: Detect Coolify installation status
|
||||||
ansible.builtin.stat:
|
ansible.builtin.include_tasks: detect.yaml
|
||||||
path: "{{ coolify_base_dir }}/source/{{ coolify_compose_files[0] }}"
|
|
||||||
register: coolify_installed
|
|
||||||
tags: always
|
tags: always
|
||||||
|
|
||||||
- name: Check Coolify container status
|
- name: Ensure Docker network exists
|
||||||
community.docker.docker_container_info:
|
become: true
|
||||||
name: "{{ item }}"
|
community.docker.docker_network:
|
||||||
loop: "{{ coolify_container_names }}"
|
name: "{{ coolify_docker_network }}"
|
||||||
register: coolify_containers
|
driver: bridge
|
||||||
when: coolify_installed.stat.exists
|
attachable: true
|
||||||
tags: always
|
state: present
|
||||||
|
tags: coolify, docker, installation
|
||||||
|
|
||||||
- name: Set Coolify health fact
|
- name: Uninstall Coolify
|
||||||
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
|
|
||||||
ansible.builtin.include_tasks: delete.yaml
|
ansible.builtin.include_tasks: delete.yaml
|
||||||
when: coolify_state == 'absent'
|
when: coolify_state == 'absent'
|
||||||
tags: coolify, deletion
|
tags: coolify, deletion
|
||||||
|
|
||||||
- name: Include installation tasks when desired and not installed
|
- name: Install Coolify
|
||||||
ansible.builtin.include_tasks: install.yaml
|
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
|
tags: coolify, installation
|
||||||
|
|
||||||
- name: Include update tasks when latest requested and already installed
|
- name: Update Coolify
|
||||||
ansible.builtin.include_tasks: update.yaml
|
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
|
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:
|
ansible.builtin.debug:
|
||||||
msg:
|
msg:
|
||||||
- "Coolify is already installed and running"
|
- "Coolify State: {{ coolify_state }}"
|
||||||
- "Containers healthy: {{ coolify_healthy | default('unknown') }}"
|
- "URL: http://{{ ansible_host }}:{{ coolify_http_port }}"
|
||||||
- "Access at: http://{{ ansible_host }}:{{ coolify_http_port }}"
|
when: coolify_state in ['present', 'latest']
|
||||||
when: (coolify_state == 'present') and coolify_installed.stat.exists | default(false)
|
|
||||||
tags: coolify, status
|
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:
|
community.docker.docker_compose_v2:
|
||||||
project_src: "{{ coolify_base_dir }}/source"
|
project_src: "{{ coolify_base_dir }}/source"
|
||||||
files: "{{ coolify_compose_files }}"
|
files: "{{ coolify_compose_files }}"
|
||||||
@@ -8,7 +26,7 @@
|
|||||||
recreate: always
|
recreate: always
|
||||||
wait: true
|
wait: true
|
||||||
wait_timeout: 300
|
wait_timeout: 300
|
||||||
tags: coolify, update
|
tags: coolify, docker, update
|
||||||
|
|
||||||
- name: Wait for Coolify HTTP to respond after update
|
- name: Wait for Coolify HTTP to respond after update
|
||||||
ansible.builtin.uri:
|
ansible.builtin.uri:
|
||||||
@@ -19,14 +37,14 @@
|
|||||||
body_format: json
|
body_format: json
|
||||||
register: coolify_health_after_update
|
register: coolify_health_after_update
|
||||||
until: coolify_health_after_update.status == 200
|
until: coolify_health_after_update.status == 200
|
||||||
retries: 10
|
retries: 20
|
||||||
delay: 10
|
delay: 15
|
||||||
tags: coolify, update, health
|
tags: coolify, update, health
|
||||||
|
|
||||||
- name: Show update success message
|
- name: Show update success message
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg:
|
msg:
|
||||||
- "Coolify updated successfully to latest version"
|
- "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 }}"
|
- "Access at: http://{{ ansible_host }}:{{ coolify_http_port }}"
|
||||||
tags: coolify, update
|
tags: coolify, update
|
||||||
|
|||||||
Reference in New Issue
Block a user