Open chrwang opened 1 year ago
Out of interest does setting ANSIBLE_CALLBACK_RESULT_FORMAT
have an effect on this? I find the output more readable when it is set to yaml
rather than the default which I guess is json
.
Out of interest does setting ANSIBLE_CALLBACK_RESULT_FORMAT have an effect on this? I find the output more readable when it is set to yaml rather than the default which I guess is json.
It does not in this case, as the format of the ok/changed/failed
lines in the play recap seem to be independent of ANSIBLE_CALLBACK_RESULT_FORMAT
and rather depends on the callback plugin itself instead. i.e. in both json
and yaml
modes with the default callback plugin I see the following format printed for the recap:
PLAY RECAP *********************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0
I think that env var controls output format from tasks themselves rather than the recap, and as molecule is looking for the lines from the recap, whatever gets printed by the task itself shouldn't matter (unless you happen to print changed=2
exactly in a debug message or something...)
I PR would be welcomed here. The right way to address this should be to enforce use of a specific callback (included in core), so we can analyze the output.
RFC: Use the ansible.posix.json
callback? That seems the most easily parseable / standard one to use.
Prerequisites
pip check
does not report any conflictsEnvironment
❯ python3 --version Python 3.11.2
What happened
What happened?
We have CI that uses molecule to automatically test pull requests to our internal company repositories of Ansible roles. We discovered that idempotent tests were showing as passed in CI, but when locally they would fail. This was narrowed down to the difference being that locally, we use the default
ansible.builtin.default
callback, while we useansible.builtin.junit
callback in CI.What did we expect to happen?
We expected tests to fail in CI as they were locally.
Root cause?
I believe this is the root cause. In
idempotence.py
, we have the following function: https://github.com/ansible/molecule/blob/01631c7c8e1d7c053bf3c57e4adafcc7badc70d4/src/molecule/command/idempotence.py#L62-L78Specifically, the following line:
molecule is detecting the changed_when status from the ansible output by specifically looking for the
changed=[some_number]
format that exists in the default callback. However, with other callback plugins Ansible doesn't print those lines and instead uses other formats. For example, inansible.builtin.json
we instead get:I'm happy to put in PRs for this, but I'd like to hear what the maintainers think about how to restructure this function. Writing a regex per parser seems highly undesirable and a pain to maintain. String parsing doesn't seem like the most ideal way to go about this, but because there's so many different callback plugin types that might be unavoidable.
Reproducing example
Gist here: https://gist.github.com/chrwang/bad5de8f073bd6a8cedc1332f2737768
Command run for success:
Command(s) run for failure: