-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make tailscale status parsing less fragile
Tailscale has an option to print out json instead. This feels like much less fragile way of checking status as we're not reliant on some heuristics and string matching. Instead we can look at very specific field. This also opens up some option in the future to look at more detailed aspects of the state and perhaps react to it in more nuanced way.
- Loading branch information
Showing
2 changed files
with
41 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
--- | ||
- name: Tailscale Status | ||
- name: Fetch Tailscale status | ||
listen: Confirm Tailscale is Connected | ||
ansible.builtin.command: tailscale status | ||
ansible.builtin.command: tailscale status --json | ||
changed_when: false | ||
register: handlers_tailscale_status | ||
register: tailscale_status | ||
|
||
- name: Debug Tailscale Status | ||
- name: Parse status JSON | ||
listen: Confirm Tailscale is Connected | ||
vars: | ||
status: "{{ tailscale_status.stdout|from_json }}" | ||
ansible.builtin.set_fact: | ||
tailscale_is_online: "{{ status.Self.Online }}" | ||
|
||
- name: Tailscale online status | ||
listen: Confirm Tailscale is Connected | ||
ansible.builtin.debug: | ||
var: handlers_tailscale_status | ||
when: | ||
- verbose | bool | ||
msg: "Online: {{ tailscale_is_online }}" | ||
when: verbose | ||
|
||
- name: Assert Tailscale is Connected | ||
listen: Confirm Tailscale is Connected | ||
ansible.builtin.assert: | ||
that: | ||
- handlers_tailscale_status.stdout | length != 0 | ||
- handlers_tailscale_status.stdout is not match('\[L\+V9o\]') | ||
- tailscale_is_online |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters