Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable json output from specific ansible commands?

Tags:

ansible

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.

like image 412
SiliconMind Avatar asked Sep 09 '15 09:09

SiliconMind


People also ask

How do you capture command output in Ansible?

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.

What does Set_fact do in Ansible?

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.

How do I format Ansible output?

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.


1 Answers

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] 
like image 61
udondan Avatar answered Sep 30 '22 08:09

udondan