如何禁用特定ansible命令的json输出? [英] How to disable json output from specific ansible commands?

查看:327
本文介绍了如何禁用特定ansible命令的json输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些Ansible命令产生的json输出对于人类来说几乎是不可读的.当人们需要检查剧本是否正确执行并引起混乱时,它会分散人们的注意力.

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.

示例命令是shellreplace-它们会产生很多无用的噪声.我该如何预防呢?简单确定|变|失败就足够了.我不需要整个JSON.

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.

推荐答案

在要禁止所有其他输出的任务上使用no_log: true.

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.

示例剧本:

- 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

示例输出:

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]

这篇关于如何禁用特定ansible命令的json输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆