Ansible 输出格式选项 [英] Ansible output formatting options

查看:55
本文介绍了Ansible 输出格式选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以选择使用 ansible(不是任何其他脚本)来格式化 ansible 输出?例如

Is there an option to format ansible output with the use of ansible (not any other scripts)? For instance

name: Show version
  sudo: true
  hosts: web_front_end
  tasks:
    - name: Create yum cache
      shell: yum makecache
    - name: Check the version of Portal
      shell: rpm -qa | grep portal
      register: portal
    - debug: msg={{portal.stdout}}
  tags:
    - portal
    - wfe

我只想得到

TASK: [debug msg={{portal.stdout}}]

部分.或者甚至有没有办法只获取shell命令输出?

part. Or even is there a way to get only the shell command output?

推荐答案

我有一个插件来格式化输出.要点是这里,但要点是:

I have a plugin to format the output. The gist is here but the gist's gist is:

# Save as <folder with your playbook>/callback_plugins/<some name>.py
# Optionally use no_log: True on your playbook/roles/tasks to suppress other output

import sys
import pprint

class CallbackModule(CallbackBase):

    def log(self, host, category, data):
        pp = pprint.PrettyPrinter(indent=2, stream=sys.stdout)
        pp.pprint(data)

这篇关于Ansible 输出格式选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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