ansible output printing unwanted things. how to fo

2019-07-26 10:29发布

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条回答
看我几分像从前
2楼-- · 2019-07-26 11:15

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[]') }}"
查看更多
登录 后发表回答