chore(coolify): refactored coolify role
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
---
|
||||
- name: Ensure source directory exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ coolify_base_dir }}/source"
|
||||
state: directory
|
||||
owner: "{{ coolify_owner }}"
|
||||
group: "{{ coolify_group }}"
|
||||
mode: "0750"
|
||||
tags: coolify, configuration
|
||||
|
||||
- name: Check if .env exists
|
||||
ansible.builtin.stat:
|
||||
path: "{{ coolify_base_dir }}/source/.env"
|
||||
register: coolify_env_file
|
||||
tags: coolify, configuration
|
||||
|
||||
- name: Generate missing secrets (only for new install)
|
||||
ansible.builtin.set_fact:
|
||||
coolify_app_key: "{{ coolify_app_key | default(lookup('password', '/dev/null length=32 chars=ascii_letters,digits'), true) }}"
|
||||
coolify_db_password: "{{ coolify_db_password | default(lookup('password', '/dev/null length=32 chars=ascii_letters,digits'), true) }}"
|
||||
coolify_redis_password: "{{ coolify_redis_password | default(lookup('password', '/dev/null length=32 chars=ascii_letters,digits'), true) }}"
|
||||
coolify_pusher_app_key: "{{ coolify_pusher_app_key | default(lookup('password', '/dev/null length=32 chars=ascii_letters,digits'), true) }}"
|
||||
coolify_pusher_app_secret: "{{ coolify_pusher_app_secret | default(lookup('password', '/dev/null length=32 chars=ascii_letters,digits'), true) }}"
|
||||
coolify_app_id: "{{ coolify_app_id | default(lookup('password', '/dev/null length=16 chars=ascii_letters,digits'), true) }}"
|
||||
coolify_pusher_app_id: "{{ coolify_pusher_app_id | default(lookup('password', '/dev/null length=16 chars=ascii_letters,digits'), true) }}"
|
||||
when: not coolify_env_file.stat.exists
|
||||
tags: coolify, configuration
|
||||
|
||||
- name: Configure .env file
|
||||
ansible.builtin.template:
|
||||
src: .env.j2
|
||||
dest: "{{ coolify_base_dir }}/source/.env"
|
||||
owner: "{{ coolify_owner }}"
|
||||
group: "{{ coolify_group }}"
|
||||
mode: "0640"
|
||||
force: false
|
||||
when: not coolify_env_file.stat.exists
|
||||
tags: coolify, configuration
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
- name: Check if Coolify is installed (compose file exists)
|
||||
ansible.builtin.stat:
|
||||
path: "{{ coolify_base_dir }}/source/{{ coolify_compose_files[0] }}"
|
||||
register: coolify_installed
|
||||
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: 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
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
- 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, start
|
||||
|
||||
- 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, start
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
- name: Stop 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
|
||||
tags: coolify, docker, stop
|
||||
Reference in New Issue
Block a user