diff options
Diffstat (limited to 'ansible/roles/caddy_add/tasks/main.yaml')
| -rw-r--r-- | ansible/roles/caddy_add/tasks/main.yaml | 97 |
1 files changed, 47 insertions, 50 deletions
diff --git a/ansible/roles/caddy_add/tasks/main.yaml b/ansible/roles/caddy_add/tasks/main.yaml index cc93518..80dffaf 100644 --- a/ansible/roles/caddy_add/tasks/main.yaml +++ b/ansible/roles/caddy_add/tasks/main.yaml @@ -1,65 +1,62 @@ --- -- tags: 'always' - # noqa: name[missing] - block: - - name: 'Ensure required vars are set' - ansible.builtin.assert: - that: - - item | mandatory - loop: - - '{{ caddy_add_hosts }}' - - '{{ caddy_add_upstream_host }}' - - '{{ caddy_add_upstream_port }}' +- name: 'Ensure required vars are set' + ansible.builtin.assert: + that: + - item | mandatory + loop: + - '{{ caddy_add_hosts }}' + - '{{ caddy_add_upstream_host }}' + - '{{ caddy_add_upstream_port }}' - - name: 'Call the Caddy API to add our new host' - ansible.builtin.uri: - url: 'http://rproxy:2019/config/apps/http/servers/serv0/routes/0' - method: 'PUT' - body_format: 'json' - status_code: 200 - body: | +- name: 'Call the Caddy API to add our new host' + ansible.builtin.uri: + url: 'http://rproxy:2019/config/apps/http/servers/serv0/routes/0' + method: 'PUT' + body_format: 'json' + status_code: 200 + body: | + { + "match": [ { - "match": [ - { - "host": {{ caddy_add_hosts | to_json }} - } - ], - "handle": [ + "host": {{ caddy_add_hosts | to_json }} + } + ], + "handle": [ + { + "handler": "subroute", + "routes": [ { - "handler": "subroute", - "routes": [ + "handle": [ { - "handle": [ + "handler": "reverse_proxy", + "upstreams": [ { - "handler": "reverse_proxy", - "upstreams": [ - { - "dial": "{{ caddy_add_upstream_host }}:{{ caddy_add_upstream_port }}" - } - ] + "dial": "{{ caddy_add_upstream_host }}:{{ caddy_add_upstream_port }}" } ] } ] } - ], - "terminal": true + ] } + ], + "terminal": true + } - - name: 'Get a copy of the new Caddy config' - delegate_to: 'localhost' - ansible.builtin.uri: - url: 'http://rproxy:2019/config' - return_content: true - register: '_current_conf' +- name: 'Get a copy of the new Caddy config' + delegate_to: 'localhost' + ansible.builtin.uri: + url: 'http://rproxy:2019/config' + return_content: true + register: '_current_conf' - - name: 'Save the new config to file' - delegate_to: 'localhost' - when: 'not ansible_check_mode' - ansible.builtin.copy: - dest: 'artifacts/caddy/{{ _file_name }}' - content: '{{ _current_conf.json }}' - mode: '644' - vars: - _file_name: 'v{{ lookup("pipe", "date +%Y%m%dT%H%M%S") }}.json' +- name: 'Save the new config to file' + delegate_to: 'localhost' + when: 'not ansible_check_mode' + ansible.builtin.copy: + dest: 'artifacts/caddy/{{ _file_name }}' + content: '{{ _current_conf.json }}' + mode: '644' + vars: + _file_name: 'v{{ lookup("pipe", "date +%Y%m%dT%H%M%S") }}.json' |
