Reputation: 1407
I'm looking for a way to get a bit more verbose output from Ansible modules for successful execution, but the only example where that appears to be implemented is the shell module, which allows to register and later print stdout and stderr. While this would be a work-around, breaking out to a shell is not good practice if built-in Ansible modules exist.
To give an example, where more verbose output from a module would be useful:
- name: upgrade all packages
yum: name=* state=latest
This updates all packages using the yum module. However, it doesn't show what (if anything) was updated.
Similar behaviour can be observed in other modules. So the actual question: Is there any Ansible switch/setting which can force more verbose output for a single task in a playbook? (I'd like to cherry pick where I get verbose output and avoid noise from everything else.)
Upvotes: 1
Views: 8307
Reputation: 1407
Ok, thanks to @xeroqu, I can answer that myself now:
- name: upgrade all packages
yum: name=* state=latest
register: result
- name: Show output
when: result|succeeded
debug: msg="{{ result.results }}"
The key is in {{result.results}}
as opposed to {{result.stdout_lines}}
. More precisely, modules appear to return a dictionary with (at least?) the following content:
ok: [localhost] => {
"msg": {
"changed": false,
"msg": "",
"rc": 0,
"results": [
"Nothing to do here, all packages are up to date"
]
}
}
That definitely gives me the verbosity I was looking for, which can be applied on a case-by-case basis.
Upvotes: 4
Reputation: 435
One idea would be having another task that would print the output of the previous task if it succeeds. I didn't test but something like this might work:
- name: upgrade all packages
yum: name=* state=latest
register: result
- name: Show output
when: result|succeeded
debug: msg="{{ result.stdout_lines }}"
Upvotes: 6