On Mon, 18 Jul 2022 18:15:19 +0200 (CEST)
dulhaver via Ansible Project <ansible-project@googlegroups.com> wrote:

>      ok: [step-0227] => {
>      "backrest_version": {
>       ...
>      "stdout": "pgBackRest 2.39",

> ... get a more usable kind of list or csv with ... domainname & the
> version of my package in question.

Get versions and create dictionary *pkg*

  ver: "{{ ansible_play_hosts|
           map('extract', hostvars, ['backrest_version', 'stdout'])|
           map('split', ' ')|map('last')|
           list }}"
  pkg: "{{ dict(ansible_play_hosts|zip(ver)) }}"

For example, given the data

  ok: [test_11] => 
    backrest_version.stdout: pgBackRest 2.39
  ok: [test_12] => 
    backrest_version.stdout: pgBackRest 2.40
  ok: [test_13] => 
    backrest_version.stdout: pgBackRest 2.41

you get the dictionary

  pkg:
    test_11: '2.39'
    test_12: '2.40'
    test_13: '2.41'

Write the CSV file

    - copy:
        dest: pkg.csv
        content: |-
          {% for k,v in pkg.items() %}
          {{ k }},{{ v }}
          {% endfor %}
      delegate_to: localhost
      run_once: true

You get

  shell> cat pkg.csv 
  test_11,2.39
  test_12,2.40
  test_13,2.41

-- 
Vladimir Botka

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20220718195413.05341a76%40gmail.com.

Attachment: pgpTjhLma65ig.pgp
Description: OpenPGP digital signature

Reply via email to