ansible输出打印不需要的东西。如何仅格式化和显示特定数据 [英] ansible output printing unwanted things. how to format and display only specific data's

查看:1861
本文介绍了ansible输出打印不需要的东西。如何仅格式化和显示特定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在centos中使用ansible 2.4,试图在远程服务器上运行以下脚本并获取输出。这里的问题是yum info输出也以json格式显示。但是我只需要显示输出。如何删除json格式。

I am using ansible 2.4 in centos, trying to run the below script in remote servers and getting the output. Here the problem is yum info output is showing with json format also. But i need to display only the output. How to remove the json format.

---

- hosts: GeneralServer

  tasks:
  - name: Checking the service status
    shell: systemctl status {{ item }}
    with_items:
        - httpd
        - crond
        - postfix
        - sshd
    register: service
  - debug: var=service
  - name: Checking the package info
    shell : yum info {{ item }}
    with_items:
        - httpd
        - postfix
    register: info
  - debug: var=info
  - name: Executing the mysql running scripts in mysql
    shell: mysql -u username --password mysql -Ns -e 'show databases;'
    register: databases
  - debug: var=databases 

我也是回调模块的新手。请帮助我解决此问题。

Also i am new in callback Module. Please help me to resolve this issue.

推荐答案

您可以尝试使用不同的回调插件来更改输出,例如:

You can try to play with different callback plugins to alter your output, e.g.:

$ ANSIBLE_STDOUT_CALLBACK=oneline ansible-playbook myplaybook.yml
$ ANSIBLE_STDOUT_CALLBACK=minimal ansible-playbook myplaybook.yml

但是通常您不会避免使用JSON,因为Ansible就是这样解释数据的。

But generally you would not avoid JSON, as it's how Ansible interprets data.

要减少信息量,可以使用不同的技术。例如 json_query 过滤器。

To reduce amount of info, you can use different technics. For example json_query filter.

类似这样的东西:

- debug:
    msg: "{{ info.results | json_query('[].stdout_lines[]') }}"

这篇关于ansible输出打印不需要的东西。如何仅格式化和显示特定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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