Skip to content

Commit

Permalink
Restart tunnels if their configuration has changed
Browse files Browse the repository at this point in the history
If an existing tunnel confiugration gets rewritten, restart the tunnel.
Also, only reload systemd when the unit file changes; it is not
neccessary to daemon-reload just to enable a new instance.
  • Loading branch information
Jordan Webb authored and papanito committed Dec 23, 2020
1 parent 363828d commit b479992
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
12 changes: 12 additions & 0 deletions tasks/add-tunnel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- name: Create config file for service '{{ item.key }}'
template:
src: config.yml.j2
dest: "{{ config_dir_tunnels }}/{{ item.key }}.yml"
register: tunnel_template
- name: Restart systemd service {{ item.key }}
systemd:
name: "{{ systemd_filename }}@{{ item.key }}"
state: restarted
enabled: yes
no_block: no
when: tunnel_template.changed
14 changes: 2 additions & 12 deletions tasks/configure-tunnels.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
- name: Create config file for service '{{ item.key }}'
template:
src: config.yml.j2
dest: "{{ config_dir_tunnels }}/{{ item.key }}.yml"
- name: Configure tunnels
include_tasks: add-tunnel.yml
with_dict: "{{ tunnels }}"
- name: Start systemd service {{ item.key }}
systemd:
name: "{{ systemd_filename }}@{{ item.key }}"
state: started
enabled: yes
daemon_reload: yes
no_block: no
with_dict: "{{ tunnels }}"
8 changes: 7 additions & 1 deletion tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
- name: Install cloudflared service for service '{{ tunnel_name }}''
template:
src: cloudflared.service.j2
dest: "{{ systemd_target_dir }}/{{ systemd_filename }}@.service"
dest: "{{ systemd_target_dir }}/{{ systemd_filename }}@.service"
register: service_template
- name: Reload systemd
systemd:
daemon_reload: yes
no_block: no
when: service_template.changed

0 comments on commit b479992

Please sign in to comment.