Let me start by saying that I hope I’m not overdoing my asks. I only do it when I’ve tried, but failed, at a solution. Nextly, I hope your kind answers help others, as well. That said, the following playbook returns packages that are set for update:
You say “the report play does not work”, but you don’t tell us in what way it doesn’t work. Is there a template error, undefined variable, or something else? Does running with -vv -D indicate anything? “Does not work” is too vague. Okay, so it didn’t do what you expected, but what did it do? Show us the play log.
For Vladimir’s solution, I get the following error:
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: PermissionError: [Errno 1] Operation not permitted: b’/tmp/.ansible_tmpkdy1r8msinstalled.txt’ → b’/tmp/installed.txt’ fatal: [bed-test-9-dy2 → localhost]: FAILED! => changed=false checksum: 543ecd635e9686d0ae4915df6ee4e9d8c13ff300 msg: ‘Unable to make b’‘/home/deploy/.ansible/tmp/ansible-tmp-1705331818.2910578-4160834-8270244954747/source’’ into to /tmp/installed.txt, failed final rename from b’‘/tmp/.ansible_tmpkdy1r8msinstalled.txt’‘: [Errno 1] Operation not permitted: b’‘/tmp/.ansible_tmpkdy1r8msinstalled.txt’’ → b’‘/tmp/installed.txt’‘’
Your ‘deploy’ user doesn’t have permission to rename a file over ‘/tmp/installed.txt’. Is there an existing file with that name? Are there unusual permissions set on ‘/tmp’ itself?
It’s bad practice to omit the ‘owner:’, ‘group:’, and ‘mode:’ of files created with the copy or template modules. There may be issues created because you’re taking the defaults. Or not. Just a thought.
Presented with those messages, the first thing I’d check is whether a file name ‘/tmp/installed.txt’ already exists on the controller.
Ah, Todd, you were right. I changed the output path, and it worked. I’m not sure why i couldn’t write to the /tmp directory, but, whatever. My last question (I hope) on this topic is how to get the output in a list format. This is what I get presently:
myhost:
The following packages will be updated[‘paho-c-1.3.13-2.el9’, ‘cpp-11.4.1-2.1.el9’, ‘glibc-headers-2.34-83.el9_3.7’, ‘gnutls-dane-3.7.6-23.el9’, ‘insights-client-3.2.2-1.el9_2’, ‘libblockdev-2.28-7.el9’, ‘libblockdev-loop-2.28-7.el9’, ‘libfastjson-0.99.9-5.el9’, ‘libvirt-daemon-9.5.0-7.el9_3’, ‘libvirt-daemon-driver-interface-9.5.0-7.el9_3’, ‘libvirt-daemon-driver-qemu-9.5.0-7.el9_3’, ‘openssl-devel-3.0.7-24.el9’, ‘python3-file-magic-5.39-14.el9’, ‘python3-pip-21.2.3-7.el9’, ‘python3-policycoreutils-3.5-2.el9’, ‘qemu-kvm-audio-pa-8.0.0-16.el9_3’, ‘qemu-kvm-core-8.0.0-16.el9_3’, ‘qemu-kvm-device-usb-host-8.0.0-16.el9_3’, ‘qemu-kvm-docs-8.0.0-16.el9_3’, ‘rpm-plugin-systemd-inhibit-4.16.1.3-25.el9’, ‘rsyslog-8.2102.0-117.el9’, ‘samba-client-4.18.6-100.el9’, ‘udisks2-iscsi-2.9.4-9.el9’, ‘fwupd-plugin-flashrom-1.8.16-1.el9’, ‘gcc-11.4.1-2.1.el9’, ‘gcc-plugin-annobin-11.4.1-2.1.el9’, ‘gnutls-utils-3.7.6-23.el9’, ‘libblockdev-fs-2.28-7.el9’, ‘libblockdev-lvm-2.28-7.el9’, ‘libblockdev-mdraid-2.28-7.el9’, ~
What kind of list? You’ve got a YAML list (with single- instead of double-quotes). You could get a JSON list (i.e. double-quotes) with
{{ output | to_json }}
or
{{ output | to_nice_json }}
This is what the output looks like in json format:
myhost:
The following packages will be updated[
“paho-c-1.3.13-2.el9”,
“cpp-11.4.1-2.1.el9”,
“glibc-headers-2.34-83.el9_3.7”,
“gnutls-dane-3.7.6-23.el9”,
“insights-client-3.2.2-1.el9_2”,
“libblockdev-2.28-7.el9”,
content: |
{% for host in ansible_play_hosts %}
{{ host }}:
The following packages will be updated
{% for p in packages.results %}
{{ p.name ~ ‘-’ ~ p.version ~ ‘-’ ~ p.release }}
{% endfor %}
Good day, everyone. I’ve continued this thread because, although I’m getting a report of packages to be updated, in that report (and in debug output), there are multiple entries for every package. This, for example is the report output for a single package: