Ease caddy stack variable setup

This commit is contained in:
Marty Oehme 2021-07-30 23:25:47 +02:00
parent 241ce71f46
commit bebdf72b19
Signed by: Marty
GPG key ID: B7538B8F50A1C800
2 changed files with 19 additions and 10 deletions

View file

@ -21,26 +21,26 @@
- name: Deploy caddy to swarm - name: Deploy caddy to swarm
community.general.docker_stack: community.general.docker_stack:
name: "{{ item.name }}" name: "{{ caddy_stack.name }}"
state: present state: present
prune: yes prune: yes
compose: compose:
- "{{ item.compose }}" - "{{ caddy_stack.compose }}"
with_items: "{{ caddy_stack }}"
when: caddy_stack is defined when: caddy_stack is defined
become: yes become: yes
tags: tags:
- docker-swarm - docker-swarm
- name: Register caddy container id - name: Get caddy container info
ansible.builtin.command: ansible.builtin.command:
cmd: docker ps -q -f name={{ item.name }} cmd: docker ps -q -f name={{ caddy_stack.name }}
with_items: "{{ caddy_stack }}"
become: yes become: yes
# bringing up the container takes some time, we have to wait
until: caddy_container_info['rc'] == 0 and caddy_container_info['stdout'] | length >= 1
register: caddy_container_info register: caddy_container_info
- name: Set fact - name: Register caddy container id
ansible.builtin.set_fact: caddy_container_id={{ caddy_container_info.results[0].stdout }} ansible.builtin.set_fact: caddy_container_id={{ caddy_container_info['stdout'] }}
notify: notify:
- debug caddy container - debug caddy container
@ -52,6 +52,15 @@
apk add curl apk add curl
become: yes become: yes
- name: Ensure caddy api is responsive
community.docker.docker_container_exec:
container: "{{ caddy_container_id }}"
command: >
curl localhost:2019/config/
until: result.rc == 0
register: result
become: yes
# TODO FIXME UP # TODO FIXME UP
# - name: Allow access to services # - name: Allow access to services
# firewalld: # firewalld:

View file

@ -1,5 +1,5 @@
--- ---
caddy_stack: caddy_stack:
- name: caddy name: caddy
compose: "{{ lookup('template', 'docker-stack.yml.j2') | from_yaml }}" compose: "{{ lookup('template', 'docker-stack.yml.j2') | from_yaml }}"