How to disable json output from specific ansible c

2020-05-24 22:24发布

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.

标签: ansible
1条回答
三岁会撩人
2楼-- · 2020-05-24 23:21

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]
查看更多
登录 后发表回答