I want to get a csv with a list of new updates in this form:
testvm-001.localdomain,ImageMagick-6.9.11.27-4.el7
testvm-001.localdomain,ImageMagick-libs-6.9.11.27-4.el7
I have a code that will display a list of updates, but I don’t know how to save it in csv in the right form.
- hosts: test
vars:
my_packages: "{{ dict(packages.results|groupby('name')) }}"
tasks:
- name: Count new update
shell: hostname
register: hostname
- dnf:
list: updates
register: packages
- debug:
msg: |
{% for name,versions in my_packages.items() %}
{% set max_ver=versions|map(attribute='version')|max %}
{% set p=versions|selectattr('version', '==', max_ver) %}
{{ hostname.stdout }},{{ name }}-{{ p.0.version }}-{{ p.0.release }}
{% endfor %}
ok: [10.0.0.2] => {
"msg": "testvm-001.localdomain,ImageMagick-6.9.11.27-4.el7 \ntestvm-001.localdomain,ImageMagick-libs-6.9.11.27-4.el7 \ntestvm-001.localdomain,LibRaw-0.19.5-6.el7 \ntestvm-001.localdomain,NetworkManager-1.32.12-1.el7 \ntestvm-001.localdomain,NetworkManager-l2tp-1.20.0-1.el7 \ntestvm-001.localdomain,NetworkManager-l2tp-gnome-1.20.0-1.el7 \ntestvm-001.localdomain,NetworkManager-libnm-1.32.12-1.el7 \ntestvm-001.localdomain,NetworkManager-libreswan-1.2.16-1.el7
...