From 62f548d05be9afecd666916e9ca4cf5ea9273a40 Mon Sep 17 00:00:00 2001 From: Sam Al-Sapti Date: Tue, 3 Oct 2023 22:00:51 +0200 Subject: [PATCH] Fix task for single service --- roles/docker/tasks/services.yml | 41 ++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/roles/docker/tasks/services.yml b/roles/docker/tasks/services.yml index 833554a0..f170f1a2 100644 --- a/roles/docker/tasks/services.yml +++ b/roles/docker/tasks/services.yml @@ -4,7 +4,7 @@ docker_network: name: external_services -- name: Service block +- name: Service block for all services loop: "{{ services | dict2items(key_name='name', value_name='vars') }}" loop_control: loop_var: service @@ -24,7 +24,7 @@ - name: Run pre-deployment tasks include_tasks: pre_deploy/{{ service.name }}.yml - when: service.vars.pre_deploy_tasks is defined and service.pre_deploy_tasks + when: service.vars.pre_deploy_tasks is defined and service.vars.pre_deploy_tasks - name: Deploy Compose stack command: docker compose up -d --remove-orphans --pull always @@ -33,20 +33,33 @@ - name: Run post-deployment tasks include_tasks: post_deploy/{{ service.name }}.yml - when: service.vars.post_deploy_tasks is defined and service.post_deploy_tasks + when: service.vars.post_deploy_tasks is defined and service.vars.post_deploy_tasks -- name: setup services - include_tasks: "services/{{ item.service.file }}" - loop: "{{ services | dict2items(value_name='service') }}" - when: single_service is not defined and - item.service.file is defined and - (item.service.disabled_in_vagrant is not defined or - not (item.service.disabled_in_vagrant and vagrant)) - -- name: setup single service - include_tasks: "services/{{ services[single_service].file }}" +- name: Service block for a single service when: single_service is defined and single_service in services and - services[single_service].file is defined and (services[single_service].disabled_in_vagrant is not defined or not (services[single_service].disabled_in_vagrant and vagrant)) + block: + - name: Create volume folder + file: + name: "{{ services[single_service].volume_folder }}" + state: directory + + - name: Upload Compose file + template: + src: compose-files/{{ single_service }}.yml.j2 + dest: "{{ services[single_service].volume_folder }}/docker-compose.yml" + + - name: Run pre-deployment tasks + include_tasks: pre_deploy/{{ single_service }}.yml + when: services[single_service].pre_deploy_tasks is defined and services[single_service].pre_deploy_tasks + + - name: Deploy Compose stack + command: docker compose up -d --remove-orphans --pull always + args: + chdir: "{{ services[single_service].volume_folder }}" + + - name: Run post-deployment tasks + include_tasks: post_deploy/{{ single_service }}.yml + when: services[single_service].post_deploy_tasks is defined and services[single_service].post_deploy_tasks