Some ansible commands produce json output that's barely readable for humans. It distracts people when they need to check if playbook executed correctly and causes confusion.
Example commands are shell
and replace
- they generate a lot of useless noise. How can I prevent this? Simple ok | changed | failed is enough. I don't need the whole JSON.
To capture the output, you need to specify your own variable into which the output will be saved. To achieve this, we use the 'register' parameter to record the output to a variable. Then use the 'debug' module to display the variable's content to standard out.
This module allows setting new variables. Variables are set on a host-by-host basis just like facts discovered by the setup module. These variables will be available to subsequent plays during an ansible-playbook run.
Ansible Output Format To change the Ansible's output format you can pass the ANSIBLE_STDOUT_CALLBACK=yaml environment variable on the command line or define the stdout_callback = yaml in Ansible configuration file.
Use no_log: true
on those tasks where you want to suppress all further output.
- shell: whatever no_log: true
I believe the only mention of this feature is within the FAQ.
Example playbook:
- hosts: - localhost gather_facts: no vars: test_list: - a - b - c tasks: - name: Test with output shell: echo "{{ item }}" with_items: test_list - name: Test w/o output shell: echo "{{ item }}" no_log: true with_items: test_list
Example output:
TASK: [Test with output] ****************************************************** changed: [localhost] => (item=a) changed: [localhost] => (item=b) changed: [localhost] => (item=c) TASK: [Test w/o output] ******************************************************* changed: [localhost] changed: [localhost] changed: [localhost]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With