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] Check mode fails to run (JSONDecodeError) #348

Open
relrod opened this issue Jun 20, 2023 · 7 comments
Open

[BUG] Check mode fails to run (JSONDecodeError) #348

relrod opened this issue Jun 20, 2023 · 7 comments
Assignees
Labels
bug This bug is confirmed and can be reproduced.

Comments

@relrod
Copy link
Contributor

relrod commented Jun 20, 2023

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!

@relrod relrod added the bug:needs-reproduction A reported bug that needs to be confirmed and reproduced. label Jun 20, 2023
@artis3n
Copy link
Owner

artis3n commented Jun 20, 2023

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?

@artis3n
Copy link
Owner

artis3n commented Jun 20, 2023

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

@relrod
Copy link
Contributor Author

relrod commented Jun 21, 2023

@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 :)

@artis3n
Copy link
Owner

artis3n commented Jun 21, 2023

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)

@artis3n artis3n self-assigned this Jun 21, 2023
@relrod
Copy link
Contributor Author

relrod commented Jun 21, 2023

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!

@artis3n artis3n added bug This bug is confirmed and can be reproduced. and removed bug:needs-reproduction A reported bug that needs to be confirmed and reproduced. labels Jun 23, 2023
@artis3n
Copy link
Owner

artis3n commented Jun 23, 2023

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

@mikroskeem
Copy link

For others who stumble upon this issue, easiest way out for now is to skip this role when running playbook in check mode

  roles:
    - role: "artis3n.tailscale"
      # ...
      when: >
        not ansible_check_mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This bug is confirmed and can be reproduced.
Projects
None yet
Development

No branches or pull requests

3 participants