Show clean yum output

Hello,

I’ve been struggling with outputting yum update results in a nice way. So I start with installing some required packages and registering the output in yum_install_required_output:

`

  • name: “Install multiple required packages to get started”
    yum:
    name:
  • deltarpm
  • yum-utils
  • zsh
  • git
  • openssh
  • openssh-server
    register: yum_install_required_output
    `

Then I try to output the yum_install_required_output registered result without the \n’s:

`

  • debug:
    msg: “ITEM {{item.split(‘\n’)}}”
    with_items: “{{yum_install_required_output.results}}”
    ignore_errors: true
    `

So as openssh and openssh-server are already installed (on this particular server), I get a list like this:

`
ok: [172.104.136.100] => (item=openssh-7.4p1-13.el7_4.x86_64 providing openssh is already installed) => {
“changed”: false,
“item”: “openssh-7.4p1-13.el7_4.x86_64 providing openssh is already installed”,
“msg”: “ITEM [u’openssh-7.4p1-13.el7_4.x86_64 providing openssh is already installed’]”
}
ok: [172.104.136.100] => (item=openssh-server-7.4p1-13.el7_4.x86_64 providing openssh-server is already installed) => {
“changed”: false,
“item”: “openssh-server-7.4p1-13.el7_4.x86_64 providing openssh-server is already installed”,
“msg”: “ITEM [u’openssh-server-7.4p1-13.el7_4.x86_64 providing openssh-server is already installed’]”
}
ok: [172.104.136.100] => (item=Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile

  • base: mirrors.linode.com
  • epel: mirror.23media.de
  • extras: mirrors.linode.com
  • updates: mirrors.linode.com
    Resolving Dependencies
    → Running transaction check
    —> Package deltarpm.x86_64 0:3.6-3.el7 will be installed
    —> Package git.x86_64 0:1.8.3.1-12.el7_4 will be installed
    → Processing Dependency: perl-Git = 1.8.3.1-12.el7_4 for package: git-1.8.3.1-12.el7_4.x86_64
    → Processing Dependency: rsync for package: git-1.8.3.1-12.el7_4.x86_64
    → Processing Dependency: perl(Term::ReadKey) for package: git-1.8.3.1-12.el7_4.x86_64
    → Processing Dependency: perl(Git) for package: git-1.8.3.1-12.el7_4.x86_64
    → Processing Dependency: perl(Error) for package: git-1.8.3.1-12.el7_4.x86_64
    → Processing Dependency: libgnome-keyring.so.0()(64bit) for package: git-1.8.3.1-12.el7_4.x86_64
    —> Package yum-utils.noarch 0:1.1.31-42.el7 will be installed
    → Processing Dependency: python-kitchen for package: yum-utils-1.1.31-42.el7.noarch
    → Processing Dependency: libxml2-python for package: yum-utils-1.1.31-42.el7.noarch
    —> Package zsh.x86_64 0:5.0.2-28.el7 will be installed
    → Running transaction check
    —> Package libgnome-keyring.x86_64 0:3.12.0-1.el7 will be installed
    —> Package libxml2-python.x86_64 0:2.9.1-6.el7_2.3 will be installed
    —> Package perl-Error.noarch 1:0.17020-2.el7 will be installed
    —> Package perl-Git.noarch 0:1.8.3.1-12.el7_4 will be installed
    —> Package perl-TermReadKey.x86_64 0:2.30-20.el7 will be installed
    —> Package python-kitchen.noarch 0:1.1.1-5.el7 will be installed
    → Processing Dependency: python-chardet for package: python-kitchen-1.1.1-5.el7.noarch
    —> Package rsync.x86_64 0:3.0.9-18.el7 will be installed
    → Running transaction check
    —> Package python-chardet.noarch 0:2.2.1-1.el7_1 will be installed
    → Finished Dependency Resolution

Dependencies Resolved

It pretty much boils down to this.
Ansible is a configuration management tool and not a reporting tool, so support for this is limited.

That being said, Ansible has a few callback plugins that alter the presentation of Ansibles output.
You could try the debug callback plugin, with that \n in msg is a newline.
If debug is not to you liking you probably need to write your own.

Hey Kai,

Thanks for your answer. It’s a bit weird imho that Ansible seems not able to just show what has been installed / updated in a clean way. But if you say there is no way to make this work with the debug module, then I guess I’ll have to believe you. Still think it’s weird though.

Grtz

I didn't say no way, just that you have limited possibilities.
You should try the debug callback before you give up.
I use that as standard an get a pretty good human readable out of it.

You can test it with
ANSIBLE_STDOUT_CALLBACK ansible-playbook <your_playbook.yml>

If you like it just add stdout_callback=debug in you ansible.cfg

Still not getting it to work. Giving up on this for today… It seems like such a trivial thing to just register and cleanly output installed / updated yum packages… I guess it’s not.

Thanks for the help anyway Kai.

Use the debug callback plugin and try this

  - debug:
      msg: |
        {% for x in yum_install_required_output.results %}
        {% for y in x.split('\n') %}
        {{ y }}
        {% endfor %}
        {% endfor %}

Kai,

Just tested this and your solution seems to do exactly what I want. I didn’t knew I could use this ninja2 syntax directly in the debug msg.

Thank you very much for your time.

Grtz