Hey all-
I’m using stat and with_items to check proper ownership of various files. Is there any way to reduce the volume of output (i.e., eliminate everything in red, below)?
rowagn@localhost:~/data-platform/oracle/ansible/db12r2$ cat test.yml
Hey all-
I’m using stat and with_items to check proper ownership of various files. Is there any way to reduce the volume of output (i.e., eliminate everything in red, below)?
rowagn@localhost:~/data-platform/oracle/ansible/db12r2$ cat test.yml
using -v should be enough to show changes but, not the whole output.
Hi,
check out the label directive for loop_control:
https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#loop-control
Cheers,
Felix
Hey Jonathan - thanks for the suggestion, but -v doesn’t help. If I include no_log: True, including -v just outputs the same:
TASK [Confirming ownership of filesystems] *************************************
ok: [localhost] => (item=(censored due to no_log)) => {“censored”: “the output has been hidden due to the fact that ‘no_log: true’ was specified for this result”}
ok: [localhost] => (item=(censored due to no_log)) => {“censored”: “the output has been hidden due to the fact that ‘no_log: true’ was specified for this result”}
Rob
Hey Felix - can you elaborate? I’m already using:
loop_control:
label: “{{ item.item }}”
As shown in my post. It doesn’t quench the output of the items. Am I missing something?
Rob
Hi Rob,
Hey Felix - can you elaborate? I'm already using:
loop_control:
label: "{{ item.item }}"As shown in my post. It doesn't quench the output of the items. Am
I missing something?
sorry, I guess I misunderstood something. The problem is that assert
always enables verbose output, so you cannot get rid of item
completely. What you can do is tidy up item so only the important
things are in there.
You could try something like
loop: |
{{ filesystems_stat.results | map(attribute='item')
> zip(filesystems_stat.results | map(attribute='stat.pw_name'))
> list }}
Then you should be able to access item.item via item.0 and
item.stat.pw_name via item.1, i.e. the rest of the task would be
assert:
that: item.1 == 'root'
loop_control:
label: "{{ item.0 }}"
(I haven't tested this, so it might contain bugs, but in principle that
should work. Note that the zip filter is Ansible specific, while the
map and list filters are generic Jinja2.)
(Also: with_items does the same as loop if you give it a simple list;
you should switch to loop in such cases, and stop using with_items if
not explicitly needed.)
Cheers,
Felix
Thanks Felix. That’s a clever idea. I tested it and I get:
ok: [localhost] => (item=/dev) => {
“changed”: false,
“item”: [
“/dev”,
“root”
],
“msg”: “All assertions passed”
}
ok: [localhost] => (item=/home) => {
“changed”: false,
“item”: [
“/home”,
“root”
],
“msg”: “All assertions passed”
}
I don’t really understand why it needs to include “item” in the dict (i.e., after => ), since it’s already present in the output (i.e., before => ), but this is better than the original. Thanks again.
Rob
So I noticed that older versions (2.1.1) of ansible didn’t have this problem, and I noticed that the verbosity of assert is caused by the following line in assert.py:
result[‘_ansible_verbose_always’] = True
If I comment that out, I get the quieter behavior I (and others, based on some reported github issues) am looking for. So can anyone explain the purpose of the above line? Why was it added to assert.py? What is _ansible_verbose_always for? Could I add another parameter to assert.py (maybe quiet) and, if set to True, then do not set result[‘_ansible_verbose_always’] to True? I appreciate I’m getting into the weeds here, but I found it curious that assert got noisy in more recent versions.
Rob
Hi Rob,
So I noticed that older versions (2.1.1) of ansible didn't have this
problem, and I noticed that the verbosity of assert is caused by the
following line in assert.py:result['_ansible_verbose_always'] = True
If I comment that out, I get the quieter behavior I (and others,
based on some reported github issues) am looking for. So can anyone
I assume you are talking about this issue:
https://github.com/ansible/ansible/issues/27124
explain the purpose of the above line? What is
_ansible_verbose_always for?
That's easy: it makes the module behave as if -v is specified on the
ansible command line: it always produces verbose output when the assert
module is used.
Why was it added to assert.py?
That's a good one. As you probably read in the issue, nobody remembers,
so it is unlikely someone suddenly can provide an explanation here
Could I add another parameter to assert.py (maybe quiet) and, if set
to True, then do not set result['_ansible_verbose_always'] to True?
Sure; that's essentially what @bcoca suggested here:
https://github.com/ansible/ansible/issues/27124#issuecomment-316855948
Feel free to create a PR which does that.
Cheers,
Felix
Thanks Felix. Working on a PR now.
Rob
Hi,
I have the same issue.
I tried this method but it didn’t work on Ansible 2.9.16.
Am I missing something ?
I’ve figured it out.
Thanks for the o.p and the contributor solution !