我想解析 yum check-update ansible 的输出,相当于仅获取人类可读格式的包列表。
到目前为止我的代码:
- name: check for updates
hosts: localhost
gather_facts: true
tasks:
- name: check for updates (yum)
yum: list=updates update_cache=true
register: yumoutput
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'
- debug: msg={{ yumoutput.stdout | from_json }}
Run Code Online (Sandbox Code Playgroud)
但我得到:
致命:[localhost]:失败!=> {“msg”:“({{ yumoutput.stdout | from_json }})上发生意外的模板类型错误:预期的字符串或缓冲区”}
编辑:完整的剧本:
---
- name: check for updates
hosts: localhost
gather_facts: true
tasks:
- name: check for updates (yum)
yum: list=updates update_cache=true
register: yumoutput
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'
- debug: var=yumoutput
msg: "{{ yumoutput.results | map(attribute='name') | list }}
Run Code Online (Sandbox Code Playgroud)
yum模块未注册stdout密钥 \xe2\x80\x95 您可以使用 来查看它debug: var=yumoutput。
您需要从字典列表中提取包名称,例如:
\n\ndebug:\n msg: "{{ yumoutput.results | map(attribute=\'name\') | list }}"\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
19296 次 |
| 最近记录: |