Move upstream logic to handler function

This commit is contained in:
Marty Oehme 2021-08-18 09:42:39 +02:00
parent 09f15d5b8e
commit 6036a91902
Signed by: Marty
GPG key ID: B7538B8F50A1C800
3 changed files with 36 additions and 18 deletions

View file

@ -1,4 +1,18 @@
## Register reverse proxy
- name: Ensure upstream directory exists
ansible.builtin.file:
path: "{{ whoami_upstream_file_dir }}"
state: directory
mode: '0755'
become: yes
listen: "update upstream"
- name: Update upstream template
ansible.builtin.template:
src: upstream.json.j2
dest: "{{ whoami_upstream_file_dir }}/upstream.json"
become: yes
listen: "update upstream"
# figure out if upstream id exists
- name: check {{ stack.name }} upstream
@ -26,6 +40,14 @@
community.docker.docker_container_exec:
container: "{{ caddy_container_id }}"
command: >
curl -X POST -H "Content-Type: application/json" -d @/stacks/{{ stack.name }}/upstream.json localhost:2019/config/apps/http/servers/{{ (whoami_use_https == True) | ternary(caddy_https_server_name, caddy_http_server_name) }}/routes/0/
curl -X POST -H "Content-Type: application/json" -d @{{ whoami_upstream_file_dir }}/upstream.json localhost:2019/config/apps/http/servers/{{ (whoami_use_https == True) | ternary(caddy_https_server_name, caddy_http_server_name) }}/routes/0/
become: yes
listen: "update upstream"
- name: Ensure upstream directory is gone again
ansible.builtin.file:
path: "{{ whoami_upstream_file_dir }}"
state: absent
become: yes
listen: "update upstream"