Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Uninstall can be broken in some scenarios #429

Open
McSim85 opened this issue Feb 13, 2024 · 2 comments
Open

[BUG] Uninstall can be broken in some scenarios #429

McSim85 opened this issue Feb 13, 2024 · 2 comments
Labels
bug:needs-reproduction A reported bug that needs to be confirmed and reproduced.

Comments

@McSim85
Copy link
Contributor

McSim85 commented Feb 13, 2024

Describe the bug
Running the role with

- name: UnInstall tailscale
  ansible.builtin.include_role:
    name: ansible_role_tailscale
  vars:
    state: absent # noqa: var-naming[no-role-prefix]
    verbose: true # noqa: var-naming[no-role-prefix]
    tailscale_tags: ['sometag']

Might fail with the error:

TASK [ansible_role_tailscale : Uninstall | De-register Tailscale Node] *********
fatal: [host]: FAILED! => changed=false 
  ansible_facts:
    discovered_interpreter_python: /usr/bin/python3
  cmd: tailscale status; tailscale logout
  delta: '0:00:00.104574'
  end: '2024-02-13 02:29:31.996263'
  msg: non-zero return code
  rc: 1
  start: '2024-02-13 02:29:31.891689'
  stderr: '500 Internal Server Error: invalid key: API key kzTEHB4CNTRL not valid'
  stderr_lines: <omitted>
  stdout: |-
    # Health check:
    #     - not logged in, last login error=invalid key: API key kzTEHB4CNTRL not valid
  
    unexpected state: NoState
  stdout_lines: <omitted>

That happens because during execution these tasks:

- name: Uninstall | Check If Tailscale Is Connected
ansible.builtin.command: tailscale status
changed_when: false
failed_when: false
register: tailscale_status
- name: Uninstall | De-register Tailscale Node
become: true
# Hack to get correct changed/ok status
ansible.builtin.shell: tailscale status; tailscale logout
register: tailscale_logout
changed_when: "'Logged out.' not in tailscale_status.stdout and 'not logged in' not in tailscale_status.stdout"
when:
# [Errno 2] No such file or directory: 'tailscale'
- tailscale_status.rc != 2
# "bash: tailscale: command not found"
- tailscale_status.rc != 127

The tailscale status exits with exit code 1 and then tailscale logout exit code 1:

root@host:~# tailscale status
# Health check:
#     - not logged in, last login error=invalid key: API key kX1yFH7CNTRL not valid

unexpected state: NoState
root@host:~# echo $?
1
root@host:~# tailscale logout
500 Internal Server Error: invalid key: API key kX1yFH7CNTRL not valid
root@host:~# echo $?
1

Expected behavior
Do not fail in such scenarios.

Additional context
PR is coming. :)

@McSim85 McSim85 added the bug:needs-reproduction A reported bug that needs to be confirmed and reproduced. label Feb 13, 2024
@McSim85
Copy link
Contributor Author

McSim85 commented Feb 13, 2024

Actually, I am thinking about running tailscale logout only if tailscale_status.rc == 0.
What do you think, @artis3n ?

@McSim85 McSim85 changed the title [BUG] Unistall can be broken in some scenarios [BUG] Uninstall can be broken in some scenarios Feb 13, 2024
@artis3n
Copy link
Owner

artis3n commented Feb 13, 2024

Why shouldn't these tasks fail, @McSim85 ? If we are unable to perform a tailscale logout (or tailscale status) then we cannot ensure that the infrastructure has been decommissioned from Tailscale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:needs-reproduction A reported bug that needs to be confirmed and reproduced.
Projects
None yet
Development

No branches or pull requests

2 participants