SiliconMind
SiliconMind

Reputation: 2179

How to disable json output from specific ansible commands?

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.

Upvotes: 39

Views: 66083

Answers (2)

blur
blur

Reputation: 218

You can use -o - one line output with ansible command (not with ansible-playbook):

ansible -o -m shell -a 'command' target

It will put hostname, command return code and command output in same line:

hostname1 | CHANGED | rc=0 | (stdout) command output
hostname2 | CHANGED | rc=0 | (stdout) command output
hostname3 | CHANGED | rc=0 | (stdout) command output

Upvotes: 0

udondan
udondan

Reputation: 59989

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]

Upvotes: 51

Related Questions