Will, worked perfectly - thanks!

On Monday, November 27, 2023 at 10:10:21 AM UTC-5 Will McDonald wrote:

> I haven't tested this but does something like:
>
>           {{ hostvars[host]['result']['stdout']|default("None", true) }} 
>
> Give the output you need?
>
> cf:
> - https://support.sendwithus.com/jinja/default/
> - 
> https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-filters.default
>
>
> On Mon, 27 Nov 2023 at 14:10, Dimitri Yioulos <[email protected]> 
> wrote:
>
>> Good day, all.
>>
>> I've created a simple package update playbook, which also creates a 
>> report of updated packages:
>>
>> - hosts: mytesthosts
>>   gather_facts: false
>>   become: yes
>>
>>   tasks:
>>     - name: install all updates
>>       yum:
>>         name: '*'
>>         update_cache: yes
>>         state: latest
>>     - name: List updated packages
>>       shell: rpm -qa --last | grep "$(date +%a\ %d\ %b\ %Y)" |cut -f 1 -d 
>> " "|sort -n
>>       register: result
>>       tags:
>>         - lsupdates
>>     - debug:
>>         msg: "{{ result.stdout_lines }}"
>>       tags:
>>         - prupdates
>>
>>     - local_action:
>>         module: copy
>>         content: |
>>           {% set t1 = now().strftime("%m/%d/%Y") %}
>>           {% for host in ansible_play_hosts %}
>>           {{ host }}:
>>
>>           The following packages were updated on {{ t1 }}
>>
>>           {{ hostvars[host]['result']['stdout'] }}
>>
>>
>>           {% endfor -%}
>>         dest: "/home/dyioulos/updates.txt"
>>       run_once: yes
>>       tags:
>>         - report
>>
>> This does almost exactly what I want it to. The report looks like this:
>>
>> test1:
>>
>> The following packages were updated on 11/27/2023
>>
>> alternatives-1.24-1.el9.x86_64
>> apr-util-1.6.1-23.el9.x86_64
>> apr-util-bdb-1.6.1-23.el9.x86_64
>> ~
>>
>> test2:
>>
>> The following packages were updated on 11/27/2023
>>
>> Note that there were no updates applied to test2. I'd like that to be 
>> reflected in the report, so that after "The following packages ...", it 
>> says "None". I would guess this requires if-then language in the inline 
>> jinja2. My searche for, and attempts at, a solution have been unsuccessful.
>>
>> Your help, as always, would be appreciated.
>>
>>
>> -- 
>> 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 [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/eed79255-29d0-49c5-88e5-9b06577933a2n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/eed79255-29d0-49c5-88e5-9b06577933a2n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2a16ca89-9d16-4009-8e67-4166e7451160n%40googlegroups.com.

Reply via email to