Reputation: 23
I want to parse the output of yum check-update ansible equivalent to get only the list of package in human readable format.
My code so far:
- 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 }}
but I get:
fatal: [localhost]: FAILED! => {"msg": "Unexpected templating type error occurred on ({{ yumoutput.stdout | from_json }}): expected string or buffer"}
EDIT: the complete playbook:
---
- 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 }}
Upvotes: 0
Views: 20827
Reputation: 21
Some minor syntax errors in the complete playbook. This did it for me
---
- 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.results | map(attribute='name') | list }}"
Upvotes: 2
Reputation: 131
In addition to the above-mentioned solution. You can use call back plugin for ease of reading the output.
Below is one of the human-readable call-back plugin:
https://github.com/n0ts/ansible-human_log
More info about call back plugins:
http://docs.ansible.com/ansible/devel/plugins/callback.html
Upvotes: -2
Reputation: 68589
yum
module does not register stdout
key ― you can see it using debug: var=yumoutput
.
You need to extract the package names from the list of dictionaries, for example:
debug:
msg: "{{ yumoutput.results | map(attribute='name') | list }}"
Upvotes: 6