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

查看:28
本文介绍了如何禁用特定 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 - 它们会产生很多无用的噪音.我怎样才能防止这种情况?简单ok |改变了|失败就够了.我不需要整个 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

我相信在 常见问题解答.

示例剧本:

- 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天全站免登陆