Ansible doesn't support looping over a block

This commit is contained in:
Sam A. 2023-10-04 19:35:52 +02:00
parent 301d1b7719
commit 3001317e20
Signed by untrusted user: samsapti
GPG key ID: CBBBE7371E81C4EA
2 changed files with 30 additions and 27 deletions

View file

@ -0,0 +1,24 @@
# vim: ft=yaml.ansible
---
- name: Create volume folder
file:
name: "{{ service.vars.volume_folder }}"
state: directory
- name: Upload Compose file
template:
src: compose-files/{{ service.name }}.yml.j2
dest: "{{ service.vars.volume_folder }}/docker-compose.yml"
- name: Run pre-deployment tasks
include_tasks: pre_deploy/{{ service.name }}.yml
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
args:
chdir: "{{ service.vars.volume_folder }}"
- name: Run post-deployment tasks
include_tasks: post_deploy/{{ service.name }}.yml
when: service.vars.post_deploy_tasks is defined and service.vars.post_deploy_tasks

View file

@ -5,35 +5,14 @@
name: external_services name: external_services
- name: Service block for all services - name: Service block for all services
include_tasks:
file: loop.yml
vars:
service: "{{ item }}"
loop: "{{ services | dict2items(key_name='name', value_name='vars') }}" loop: "{{ services | dict2items(key_name='name', value_name='vars') }}"
loop_control:
loop_var: service
when: single_service is not defined and when: single_service is not defined and
(service.vars.disabled_in_vagrant is not defined or (item.vars.disabled_in_vagrant is not defined or
not (service.vars.disabled_in_vagrant and vagrant)) not (item.vars.disabled_in_vagrant and vagrant))
block:
- name: Create volume folder
file:
name: "{{ service.vars.volume_folder }}"
state: directory
- name: Upload Compose file
template:
src: compose-files/{{ service.name }}.yml.j2
dest: "{{ service.vars.volume_folder }}/docker-compose.yml"
- name: Run pre-deployment tasks
include_tasks: pre_deploy/{{ service.name }}.yml
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
args:
chdir: "{{ service.vars.volume_folder }}"
- name: Run post-deployment tasks
include_tasks: post_deploy/{{ service.name }}.yml
when: service.vars.post_deploy_tasks is defined and service.vars.post_deploy_tasks
- name: Service block for a single service - name: Service block for a single service
when: single_service is defined and single_service in services and when: single_service is defined and single_service in services and