我有一个简单的剧本来查询包版本
---
- name: version find
hosts: all
become: yes
tasks:
- name: query
shell: *shell command*
register: info
no_log: true
- debug:
msg: " {{inventory_hostname}} blah {{info.stdout}}blah"
Run Code Online (Sandbox Code Playgroud)
我得到的输出包含大量垃圾,这使得在不进行编辑的情况下解析/使用输出变得困难:
ok: [hostname] => {
"msg": " *hostname* blah *info* blah"
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试找到一种解决方案,只返回不带“ok:”的消息,以及随之而来的 JSON 式垃圾。
我尝试no_log:True在 YAML 文件和 ansible.cfg 文件中进行设置,但没有成功。
使用回调community.general.diy(自己动手)。看
shell> ansible-doc -t callback community.general.diy
Run Code Online (Sandbox Code Playgroud)
例如,
shell> ansible-doc -t callback community.general.diy
Run Code Online (Sandbox Code Playgroud)
给出
shell> cat pb.yml
- hosts: localhost
tasks:
- command: uname -o
register: info
- debug:
msg: ""
vars:
ansible_callback_diy_runner_on_ok_msg: |
msg: {{ inventory_hostname }} {{ info.stdout }}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
204 次 |
| 最近记录: |