Linux ansible yum检查更新解析输出以获得包列表
我想解析yum-check-update-ansible-equivalent的输出,以便只获得可读格式的包列表 到目前为止,我的代码是:Linux ansible yum检查更新解析输出以获得包列表,linux,ansible,yum,Linux,Ansible,Yum,我想解析yum-check-update-ansible-equivalent的输出,以便只获得可读格式的包列表 到目前为止,我的代码是: - name: check for updates hosts: localhost gather_facts: true tasks: - name: check for updates (yum) yum: list=updates update_cache=true register: yumoutput when:
- 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 }}
但我得到:
致命:[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 }}
yum
模块未注册stdout
键―您可以使用debug:var=yumoutput
查看它
您需要从字典列表中提取包名,例如:
debug:
msg: "{{ yumoutput.results | map(attribute='name') | list }}"
yum
模块未注册stdout
键―您可以使用debug:var=yumoutput
查看它
您需要从字典列表中提取包名,例如:
debug:
msg: "{{ yumoutput.results | map(attribute='name') | list }}"
除了上述解决方案之外。您可以使用回调插件来轻松读取输出 下面是一个可读的回调插件:
https://github.com/n0ts/ansible-human_log
有关回拨插件的更多信息:
http://docs.ansible.com/ansible/devel/plugins/callback.html
除了上述解决方案之外。您可以使用回调插件来轻松读取输出 下面是一个可读的回调插件:
https://github.com/n0ts/ansible-human_log
有关回拨插件的更多信息:
http://docs.ansible.com/ansible/devel/plugins/callback.html
“debug:var”很好理解,但是对于您的调试示例,我有:[警告]:忽略无效属性:msgMost可能是因为您没有保留正确的缩进。我用完整的剧本更新了原始问题“debug:var”很好理解,但是对于您的调试示例,我有:[警告]:忽略无效属性:msgMost可能是因为您没有保留正确的缩进。我用完整的剧本更新了原始问题