--- # Input checks. Imported first in main.yml with tags: always, so a bad input fails before any # change. The argument spec (types) runs before this file. # The repository suite and the source list follow the host's release, read from gathered facts. - name: Require Ubuntu ansible.builtin.assert: that: - ansible_facts['distribution'] | default('') == 'Ubuntu' fail_msg: >- tailscale supports Ubuntu only (found: {{ ansible_facts['distribution'] | default('no gathered facts') }}). The role reads gathered facts, so run it in a play that gathers them. quiet: true # Read-only, so it also runs under --check. A missing binary or a daemon that is not up counts as # not Running. - name: Read the Tailscale backend state before any change become: true ansible.builtin.command: tailscale status --json register: __tailscale_status_before changed_when: false failed_when: false check_mode: false when: tailscale_up | bool # tailscale up runs when the node is not Running, and a removal logs it out first, so then the # key is needed. - name: Require an auth key when tailscale up will run ansible.builtin.assert: that: - tailscale_auth_key is defined - tailscale_auth_key is string - tailscale_auth_key | trim | length > 0 fail_msg: >- tailscale_auth_key must be a non-empty string: tailscale_up is true and the node is not Running (or tailscale_remove is true), so the role runs tailscale up. Set the key, normally from a vaulted variable, or set tailscale_up to false. quiet: true when: - tailscale_up | bool - >- tailscale_remove | bool or (__tailscale_status_before.stdout | default('{}', true) | from_json).BackendState | default('NoState') != 'Running'