artis3n/ansible-role-tailscale

[BUG] Check mode fails to run (JSONDecodeError)

relrod opened this issue · 7 comments

relrod commented

Describe the bug

Since #328 check mode no longer works because the JSON parsing tries to parse an empty string which raises an exception.

To Reproduce
Try to run the role with check mode enabled.

Expected behavior
The same behavior as before #328 ;)

Screenshots

TASK [artis3n.tailscale : Install | Fetch Tailscale status] ********************
skipping: [app03] => {"changed": false, "cmd": ["tailscale", "status", "--json"], "delta": null, "end": null, "msg": "Command would have run if not in check mode", "rc": 0, "start": null, "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}

TASK [artis3n.tailscale : Install | Parse status JSON] *************************
fatal: [app03]: FAILED! => {"msg": "An unhandled exception occurred while templating '{{ tailscale_status.stdout | from_json }}'. Error was a <class 'json.decoder.JSONDecodeError'>, original message: Expecting value: line 1 column 1 (char 0)"}

Target (please complete the following information):

  • OS: RHEL
  • Ansible version: latest stable
  • artis3n.tailscale version: latest release
  • Tailscale version (set verbose to true): irrelevant (check mode is on, so it shouldn't actually shell out to tailscale)

Additional context

I think it's just a matter of needing to test if check mode is enabled and skip some steps in the role, but I haven't looked too closely. I'm happy to test if/when there is a patch.

Thanks for your awesome work on this role!

Hmm, I understand the command module doesn't run in check mode because it allows arbitrary things to run, but the tailscale status command is pure data collection. I wonder if we should note this command should run during a check mode execution.

To force a task to run in normal mode and make changes to the system, even when the playbook is called with --check, set check_mode: false

https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_checkmode.html#id2

@relrod What do you think about me making that adjustment?

Note to self: also create a molecule test to run the playbook under check mode to catch issues where we will break adherence.

relrod commented

@artis3n thanks for the super fast response! Yeah I think either way is fine. I haven't delved into the role enough to know what it uses the data for, but I think there are really two possible solutions: Either do what you said and have the command run even in check mode, or skip the tasks that depend on it, when check mode is active.

I personally don't have a preference. If you do it the way you said, I guess we'd need to make sure that the command was successful. Because if we're in check mode and running the role for the first time, then tailscale likely might not even be installed on the system yet :)

Good point 🤔 My first step will be to add the test running --check and then go from there to see how to best support in this role, because I do want it to run correctly in check mode.

ansible/molecule#128 (comment)

relrod commented

Thanks. I have some playbooks that run nightly just to check for configuration drift. This had been alerting for a while, but I only just found some time to look into it and open the ticket. Thanks again for the quick response!

As-is, when running in check mode I see a failure at the beginning of the role:
image
image