refactor(roles/dokploy): refactored dokploy role
This commit is contained in:
@@ -13,7 +13,8 @@ dokploy_traefik_image: traefik:v3.6.1
|
|||||||
|
|
||||||
dokploy_postgres_user: dokploy
|
dokploy_postgres_user: dokploy
|
||||||
dokploy_postgres_db: dokploy
|
dokploy_postgres_db: dokploy
|
||||||
dokploy_postgres_password: "{{ lookup('password', '/dev/null chars=ascii_letters,digits length=32') }}"
|
# Must be explicitly set per-host or in vault — left empty to fail loudly
|
||||||
|
dokploy_postgres_password: ""
|
||||||
|
|
||||||
dokploy_docker_network: dokploy-network
|
dokploy_docker_network: dokploy-network
|
||||||
|
|
||||||
|
|||||||
@@ -9,14 +9,22 @@
|
|||||||
- dokploy
|
- dokploy
|
||||||
- dokploy-redis
|
- dokploy-redis
|
||||||
- dokploy-postgres
|
- dokploy-postgres
|
||||||
ignore_errors: true
|
register: _dokploy_remove_services
|
||||||
|
failed_when:
|
||||||
|
- _dokploy_remove_services is failed
|
||||||
|
- "'could not find' not in (_dokploy_remove_services.msg | default('') | lower)"
|
||||||
|
- "'not found' not in (_dokploy_remove_services.msg | default('') | lower)"
|
||||||
tags: dokploy, deletion
|
tags: dokploy, deletion
|
||||||
|
|
||||||
- name: Leave Docker Swarm
|
- name: Leave Docker Swarm
|
||||||
become: true
|
become: true
|
||||||
community.docker.docker_swarm:
|
community.docker.docker_swarm:
|
||||||
state: absent
|
state: absent
|
||||||
ignore_errors: true
|
register: _dokploy_swarm_leave
|
||||||
|
failed_when:
|
||||||
|
- _dokploy_swarm_leave is failed
|
||||||
|
- "'not part of a swarm' not in (_dokploy_swarm_leave.msg | default('') | lower)"
|
||||||
|
- "'not a swarm manager' not in (_dokploy_swarm_leave.msg | default('') | lower)"
|
||||||
tags: dokploy, deletion
|
tags: dokploy, deletion
|
||||||
|
|
||||||
- name: Remove Dokploy network
|
- name: Remove Dokploy network
|
||||||
@@ -24,10 +32,14 @@
|
|||||||
community.docker.docker_network:
|
community.docker.docker_network:
|
||||||
name: "{{ dokploy_docker_network }}"
|
name: "{{ dokploy_docker_network }}"
|
||||||
state: absent
|
state: absent
|
||||||
ignore_errors: true
|
register: _dokploy_remove_network
|
||||||
|
failed_when:
|
||||||
|
- _dokploy_remove_network is failed
|
||||||
|
- "'not found' not in (_dokploy_remove_network.msg | default('') | lower)"
|
||||||
tags: dokploy, deletion
|
tags: dokploy, deletion
|
||||||
|
|
||||||
- name: Remove Dokploy configuration directory
|
- name: Remove Dokploy configuration directory
|
||||||
|
become: true
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ dokploy_config_dir }}"
|
path: "{{ dokploy_config_dir }}"
|
||||||
state: absent
|
state: absent
|
||||||
@@ -43,13 +55,17 @@
|
|||||||
- dokploy-postgres-database
|
- dokploy-postgres-database
|
||||||
- redis-data-volume
|
- redis-data-volume
|
||||||
- dokploy-docker-config
|
- dokploy-docker-config
|
||||||
|
register: _dokploy_remove_volumes
|
||||||
|
failed_when:
|
||||||
|
- _dokploy_remove_volumes is failed
|
||||||
|
- "'no such volume' not in (_dokploy_remove_volumes.msg | default('') | lower)"
|
||||||
|
- "'not found' not in (_dokploy_remove_volumes.msg | default('') | lower)"
|
||||||
when: dokploy_remove_data_on_absent | bool
|
when: dokploy_remove_data_on_absent | bool
|
||||||
ignore_errors: true
|
|
||||||
tags: dokploy, deletion, volumes
|
tags: dokploy, deletion, volumes
|
||||||
|
|
||||||
- name: Display uninstallation message
|
- name: Display uninstallation message
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg:
|
msg:
|
||||||
- "Dokploy has been uninstalled"
|
- "Dokploy has been uninstalled"
|
||||||
- "Application data preserved: {{ not dokploy_remove_data_on_absent }}"
|
- "Data removed: {{ dokploy_remove_data_on_absent | bool }}"
|
||||||
tags: dokploy, deletion
|
tags: dokploy, deletion
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
- name: Check if Docker is installed
|
- name: Check if Docker is installed
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: docker --version
|
cmd: docker --version
|
||||||
ignore_errors: false
|
|
||||||
changed_when: false
|
changed_when: false
|
||||||
tags: dokploy, docker, installation
|
tags: dokploy, docker, installation
|
||||||
|
|
||||||
@@ -17,35 +16,39 @@
|
|||||||
become: true
|
become: true
|
||||||
community.docker.docker_swarm:
|
community.docker.docker_swarm:
|
||||||
state: absent
|
state: absent
|
||||||
ignore_errors: true
|
register: _dokploy_swarm_leave
|
||||||
|
failed_when:
|
||||||
|
- _dokploy_swarm_leave is failed
|
||||||
|
- "'not part of a swarm' not in (_dokploy_swarm_leave.msg | default('') | lower)"
|
||||||
|
- "'not a swarm manager' not in (_dokploy_swarm_leave.msg | default('') | lower)"
|
||||||
tags: dokploy, swarm, installation
|
tags: dokploy, swarm, installation
|
||||||
|
|
||||||
- name: Determine advertise address
|
- name: Determine advertise address
|
||||||
|
tags: dokploy, network, installation
|
||||||
block:
|
block:
|
||||||
- name: Get private IP address
|
- name: Get private IP address
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
private_ip: "{{ ansible_default_ipv4.address }}"
|
dokploy_private_ip: "{{ ansible_default_ipv4.address }}"
|
||||||
when: dokploy_advertise_addr == ""
|
when: dokploy_advertise_addr == ""
|
||||||
|
|
||||||
- name: Set advertise address
|
- name: Set advertise address
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
effective_advertise_addr: "{{ dokploy_advertise_addr | default(private_ip) }}"
|
dokploy_effective_advertise_addr: "{{ dokploy_advertise_addr | default(dokploy_private_ip) }}"
|
||||||
tags: dokploy, network, installation
|
|
||||||
|
|
||||||
- name: Validate advertise address
|
- name: Validate advertise address
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- effective_advertise_addr is defined
|
- dokploy_effective_advertise_addr is defined
|
||||||
- effective_advertise_addr != ""
|
- dokploy_effective_advertise_addr != ""
|
||||||
msg: "Could not determine advertise address. Please set dokploy_advertise_addr variable."
|
fail_msg: "Could not determine advertise address. Please set dokploy_advertise_addr variable."
|
||||||
tags: dokploy, network, installation
|
tags: dokploy, network, installation
|
||||||
|
|
||||||
- name: Initialize Docker Swarm
|
- name: Initialize Docker Swarm
|
||||||
become: true
|
become: true
|
||||||
community.docker.docker_swarm:
|
community.docker.docker_swarm:
|
||||||
state: present
|
state: present
|
||||||
advertise_addr: "{{ effective_advertise_addr }}"
|
advertise_addr: "{{ dokploy_effective_advertise_addr }}"
|
||||||
listen_addr: "{{ effective_advertise_addr }}"
|
listen_addr: "{{ dokploy_effective_advertise_addr }}"
|
||||||
tags: dokploy, swarm, installation
|
tags: dokploy, swarm, installation
|
||||||
|
|
||||||
- name: Create dokploy overlay network
|
- name: Create dokploy overlay network
|
||||||
@@ -61,7 +64,7 @@
|
|||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ dokploy_config_dir }}"
|
path: "{{ dokploy_config_dir }}"
|
||||||
state: directory
|
state: directory
|
||||||
mode: "0777"
|
mode: "0755"
|
||||||
tags: dokploy, files, installation
|
tags: dokploy, files, installation
|
||||||
|
|
||||||
- name: Pull all service images (when update all services requested)
|
- name: Pull all service images (when update all services requested)
|
||||||
@@ -188,7 +191,7 @@
|
|||||||
constraints:
|
constraints:
|
||||||
- "node.role=={{ dokploy_constraint_node_role }}"
|
- "node.role=={{ dokploy_constraint_node_role }}"
|
||||||
env:
|
env:
|
||||||
ADVERTISE_ADDR: "{{ effective_advertise_addr }}"
|
ADVERTISE_ADDR: "{{ dokploy_effective_advertise_addr }}"
|
||||||
DATABASE_URL: "postgres://{{ dokploy_postgres_user }}:{{ dokploy_postgres_password }}@dokploy-postgres:5432/{{ dokploy_postgres_db }}"
|
DATABASE_URL: "postgres://{{ dokploy_postgres_user }}:{{ dokploy_postgres_password }}@dokploy-postgres:5432/{{ dokploy_postgres_db }}"
|
||||||
state: present
|
state: present
|
||||||
tags: dokploy, main, installation
|
tags: dokploy, main, installation
|
||||||
@@ -268,6 +271,6 @@
|
|||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg:
|
msg:
|
||||||
- "Dokploy installed successfully"
|
- "Dokploy installed successfully"
|
||||||
- "Using advertise address: {{ effective_advertise_addr }}"
|
- "Using advertise address: {{ dokploy_effective_advertise_addr }}"
|
||||||
- "Access at: http://{{ ansible_host }}:{{ dokploy_http_port }}"
|
- "Access at: http://{{ ansible_host }}:{{ dokploy_http_port }}"
|
||||||
tags: dokploy, installation
|
tags: dokploy, installation
|
||||||
|
|||||||
@@ -3,7 +3,18 @@
|
|||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- dokploy_state in ['present', 'absent', 'latest']
|
- dokploy_state in ['present', 'absent', 'latest']
|
||||||
msg: "dokploy_state must be one of: present, absent, latest"
|
fail_msg: "dokploy_state must be one of: present, absent, latest"
|
||||||
|
tags: always
|
||||||
|
|
||||||
|
- name: Validate dokploy_postgres_password is set
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- dokploy_postgres_password | default('', true) | length > 0
|
||||||
|
fail_msg: >-
|
||||||
|
dokploy_postgres_password must be explicitly set per-host or in vault.
|
||||||
|
It cannot be left empty.
|
||||||
|
quiet: true
|
||||||
|
when: dokploy_state in ['present', 'latest']
|
||||||
tags: always
|
tags: always
|
||||||
|
|
||||||
- name: Check if Dokploy services exist
|
- name: Check if Dokploy services exist
|
||||||
@@ -11,7 +22,7 @@
|
|||||||
community.docker.docker_swarm_service_info:
|
community.docker.docker_swarm_service_info:
|
||||||
name: dokploy
|
name: dokploy
|
||||||
register: dokploy_services
|
register: dokploy_services
|
||||||
ignore_errors: true
|
failed_when: false
|
||||||
tags: always
|
tags: always
|
||||||
|
|
||||||
- name: Include deletion tasks if state is absent
|
- name: Include deletion tasks if state is absent
|
||||||
|
|||||||
Reference in New Issue
Block a user