ansible output printing unwanted things. how to format and display only specific data's

谁说我不能喝 提交于 2019-12-24 01:41:31

问题


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.

Is it possibile to display only stdout_lines values only.


回答1:


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

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

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

Something like this:

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


来源:https://stackoverflow.com/questions/47448071/ansible-output-printing-unwanted-things-how-to-format-and-display-only-specific

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!