问题
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