itChi
itChi

Reputation: 672

Ansible Update yum human friendly output

I'd like to get a better output format from Ansible when running yum updates

My playbook:

- hosts: all
  user: ansbl
  gather_facts: true
  become: true
  tasks:
    - name: Check YUM Updates
      yum:
        name: '*'
        state: latest
        update_cache: yes
        skip_broken: yes
      register: yum_output
      when: ansible_facts['os_family'] == "RedHat"
      check_mode: yes

    - debug:
        msg: "{{ yum_output.changes.updated }}"
      when: ansible_facts['distribution'] == "RedHat"

My output:

TASK [debug] *******************************************************************
ok: [myhost] => {
    "msg": [
        [
            "nss", 
            "3.44.0-7.el7_7.x86_64 from rhui-rhel-7-server-rhui-rpms"
        ], 
        [
            "kernel-tools", 
            "3.10.0-1062.9.1.el7.x86_64 from rhui-rhel-7-server-rhui-rpms"
        ], 
        [
            "nss-softokn-freebl", 
            "3.44.0-8.el7_7.x86_64 from rhui-rhel-7-server-rhui-rpms"
        ]
    ]
}

Desired output:

TASK [debug] *******************************************************************
ok: [myhost] => {
    "msg": [
        "nss", "3.44.0-7.el7_7.x86_64 from rhui-rhel-7-server-rhui-rpms"
        "kernel-tools", "3.10.0-1062.9.1.el7.x86_64 from rhui-rhel-7-server-rhui-rpms"
        "nss-softokn-freebl", "3.44.0-8.el7_7.x86_64 from rhui-rhel-7-server-rhui-rpms"
    ]
}

I've seen a method of collecting updated packages from dpkg as a separate task, but if possible I'd like to contain this in one debug task. I've tried piping to list and join but this returned the same output result.

Upvotes: 0

Views: 595

Answers (1)

Vladimir Botka
Vladimir Botka

Reputation: 68179

Try this one

- debug:
    msg: "{{ msg[:-1].split('\n') }}"
  vars:
    msg: |-
      {% for pkg in yum_output.changes.updated %}
      {{ pkg.0 }}, {{ pkg.1 }}
      {% endfor %}
  when: ansible_facts['distribution'] == "RedHat"

Upvotes: 1

Related Questions