# Another report creation problem

**URL:** <https://forum.ansible.com/t/another-report-creation-problem/38653>\
**Category:** Ansible Project\
**Created:** [January 15, 2024, 1:00pm UTC](https://forum.ansible.com/t/another-report-creation-problem/38653 "2024-01-15T13:00:12Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [January 15, 2024, 1:00pm UTC](https://forum.ansible.com/t/another-report-creation-problem/38653/1 "2024-01-15T13:00:12Z")

</div>

Good morning.

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:

---

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [January 15, 2024, 1:06pm UTC](https://forum.ansible.com/t/another-report-creation-problem/38653/2 "2024-01-15T13:06:57Z")

</div>

Fro what it may be worth, using the yaml stdout\_callback, the output of debug looks like this:

ok: [myhost] =\>  
msg:

- 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

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [January 15, 2024, 2:21pm UTC](https://forum.ansible.com/t/another-report-creation-problem/38653/3 "2024-01-15T14:21:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [January 15, 2024, 3:02pm UTC](https://forum.ansible.com/t/another-report-creation-problem/38653/4 "2024-01-15T15:02:46Z")

</div>

Create the variable(s) \*output\*

&nbsp;&nbsp;&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;output: "{{ packages.results  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\>json\_query('.[name, version, release]')  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\>map('join','-') }}"

Then, use it(them) in the \*content\*

&nbsp;&nbsp;&nbsp;&nbsp;- copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /tmp/installed.txt  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content: |  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{% for host in ansible\_play\_hosts %}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ host }}:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The following packages will be updated  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ hostvars[host]['output']|to\_nice\_yaml }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{% endfor %}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;run\_once: true  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delegate\_to: localhost

---

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [January 15, 2024, 3:04pm UTC](https://forum.ansible.com/t/another-report-creation-problem/38653/5 "2024-01-15T15:04:55Z")

</div>

As I have written the playbook above, here’s the error, which I hope is enough for troubleshooting purposes:

**ESTABLISH LOCAL CONNECTION FOR USER: deploy**  
 **EXEC /bin/sh -c ‘echo ~deploy && sleep 0’**  
 **EXEC /bin/sh -c ‘( umask 77 && mkdir -p “`echo /home/deploy/.ansible/tmp`”&& mkdir “`echo /home/deploy/.ansible/tmp/ansible-tmp-1705330892.3380399-4159921-3325212893501`” && echo ansible-tmp-1705330892.3380399-4159921-3325212893501=“`echo /home/deploy/.ansible/tmp/ansible-tmp-1705330892.3380399-4159921-3325212893501`” ) && sleep 0’**  
**Using module file /usr/local/lib/python3.9/site-packages/ansible/modules/stat.py**  
 **PUT /home/deploy/.ansible/tmp/ansible-local-4159897gzoguc4w/tmphdv1no20 TO /home/deploy/.ansible/tmp/ansible-tmp-1705330892.3380399-4159921-3325212893501/AnsiballZ\_stat.py**  
 **EXEC /bin/sh -c ‘chmod u+x /home/deploy/.ansible/tmp/ansible-tmp-1705330892.3380399-4159921-3325212893501/ /home/deploy/.ansible/tmp/ansible-tmp-1705330892.3380399-4159921-3325212893501/AnsiballZ\_stat.py && sleep 0’**  
 **EXEC /bin/sh -c ‘/usr/bin/env python /home/deploy/.ansible/tmp/ansible-tmp-1705330892.3380399-4159921-3325212893501/AnsiballZ\_stat.py && sleep 0’**  
 **PUT /home/deploy/.ansible/tmp/ansible-local-4159897gzoguc4w/tmpi\_3sa5v9 TO /home/deploy/.ansible/tmp/ansible-tmp-1705330892.3380399-4159921-3325212893501/source**  
 **EXEC /bin/sh -c ‘chmod u+x /home/deploy/.ansible/tmp/ansible-tmp-1705330892.3380399-4159921-3325212893501/ /home/deploy/.ansible/tmp/ansible-tmp-1705330892.3380399-4159921-3325212893501/source && sleep 0’**  
**Using module file /usr/local/lib/python3.9/site-packages/ansible/modules/copy.py**  
 **PUT /home/deploy/.ansible/tmp/ansible-local-4159897gzoguc4w/tmpyre28n8\_ TO /home/deploy/.ansible/tmp/ansible-tmp-1705330892.3380399-4159921-3325212893501/AnsiballZ\_copy.py**  
 **EXEC /bin/sh -c ‘chmod u+x /home/deploy/.ansible/tmp/ansible-tmp-1705330892.3380399-4159921-3325212893501/ /home/deploy/.ansible/tmp/ansible-tmp-1705330892.3380399-4159921-3325212893501/AnsiballZ\_copy.py && sleep 0’**  
 **EXEC /bin/sh -c ‘/usr/bin/env python /home/deploy/.ansible/tmp/ansible-tmp-1705330892.3380399-4159921-3325212893501/AnsiballZ\_copy.py && sleep 0’**  
 **EXEC /bin/sh -c ‘rm -f -r /home/deploy/.ansible/tmp/ansible-tmp-1705330892.3380399-4159921-3325212893501/ \> /dev/null 2\>&1 && sleep 0’**  
**The full traceback is:**  
**Traceback (most recent call last):**  
**File “/tmp/ansible\_ansible.legacy.copy\_payload\_rmpe1ef8/ansible\_ansible.legacy.copy\_payload.zip/ansible/module\_utils/basic.py”, line 1700, in atomic\_move**  
**os.rename(b\_src, b\_dest)**  
**PermissionError: [Errno 1] Operation not permitted: b’/home/deploy/.ansible/tmp/ansible-tmp-1705330892.3380399-4159921-3325212893501/source’ → b’/tmp/installed.txt’**

**During handling of the above exception, another exception occurred:**

**Traceback (most recent call last):**  
**File “/tmp/ansible\_ansible.legacy.copy\_payload\_rmpe1ef8/ansible\_ansible.legacy.copy\_payload.zip/ansible/module\_utils/basic.py”, line 1759, in atomic\_move**  
**os.rename(b\_tmp\_dest\_name, b\_dest)**  
**PermissionError: [Errno 1] Operation not permitted: b’/tmp/.ansible\_tmp162o24fxinstalled.txt’ → b’/tmp/installed.txt’**  
**fatal: [bed-test-9-dy2 → localhost]: FAILED! =\> changed=false**  
**checksum: 590d9e59d7b819e4c8fb2068a91aec5e760afc8e**  
**diff: []**  
**invocation:**  
**module\_args:**  
**\_original\_basename: tmpi\_3sa5v9**  
**attributes: null**  
**backup: false**  
**checksum: 590d9e59d7b819e4c8fb2068a91aec5e760afc8e**  
**content: null**  
**dest: /tmp/installed.txt**  
**directory\_mode: null**  
**follow: false**  
**force: true**  
**group: null**  
**local\_follow: null**  
**mode: null**  
**owner: null**  
**remote\_src: null**  
**selevel: null**  
**serole: null**  
**setype: null**  
**seuser: null**  
**src: /home/deploy/.ansible/tmp/ansible-tmp-1705330892.3380399-4159921-3325212893501/source**  
**unsafe\_writes: false**  
**validate: null**  
**msg: ‘Unable to make b’‘/home/deploy/.ansible/tmp/ansible-tmp-1705330892.3380399-4159921-3325212893501/source’’ into to /tmp/installed.txt, failed final rename from b’‘/tmp/.ansible\_tmp162o24fxinstalled.txt’‘: [Errno 1] Operation not permitted: b’‘/tmp/.ansible\_tmp162o24fxinstalled.txt’’ → b’‘/tmp/installed.txt’‘’**

---

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [January 15, 2024, 3:19pm UTC](https://forum.ansible.com/t/another-report-creation-problem/38653/6 "2024-01-15T15:19:08Z")

</div>

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’‘’**

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [January 15, 2024, 3:31pm UTC](https://forum.ansible.com/t/another-report-creation-problem/38653/7 "2024-01-15T15:31:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [January 15, 2024, 3:53pm UTC](https://forum.ansible.com/t/another-report-creation-problem/38653/8 "2024-01-15T15:53:29Z")

</div>

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’, ~

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [January 15, 2024, 4:12pm UTC](https://forum.ansible.com/t/another-report-creation-problem/38653/9 "2024-01-15T16:12:48Z")

</div>

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 }}

What kind of list did you have in mind?

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [January 15, 2024, 4:24pm UTC](https://forum.ansible.com/t/another-report-creation-problem/38653/10 "2024-01-15T16:24:55Z")

</div>

> I changed the output path, and it worked. I’m not sure why i couldn’t write to the /tmp directory

ls -ld /tmp /tmp/installed.txt  
would probably explain it.

---

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [January 15, 2024, 5:00pm UTC](https://forum.ansible.com/t/another-report-creation-problem/38653/11 "2024-01-15T17:00:18Z")

</div>

Todd, just before your last posy, i tried **| to\_nice\_json** and **| to\_nice\_yaml** , both of which worked, to a point.

Here’s what I’m after:

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

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”,

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [January 15, 2024, 5:14pm UTC](https://forum.ansible.com/t/another-report-creation-problem/38653/12 "2024-01-15T17:14:51Z")

</div>

content: |  
{% for host in ansible\_play\_hosts %}  
{{ host }}:  
The following packages will be updated  
{% for p in packages.results %}  
{{ [p.name](http://p.name) ~ ‘-’ ~ p.version ~ ‘-’ ~ p.release }}  
{% endfor %}

{% endfor %}

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [January 15, 2024, 5:15pm UTC](https://forum.ansible.com/t/another-report-creation-problem/38653/13 "2024-01-15T17:15:25Z")

</div>

I think you’d need to explicitly iterate over the list for that:

content: |  
{% for host in ansible\_play\_hosts %}  
{{ host }}:  
The following packages will be updated:

{% for package in hostvars[host][‘output’] %}  
{{ package }}  
{% endfor %}  
{% endfor %}

---

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [January 26, 2024, 2:24pm UTC](https://forum.ansible.com/t/another-report-creation-problem/38653/14 "2024-01-26T14:24:28Z")

</div>

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:

[deploy@myhost]$ grep grub2-common /home/deploy/updates.txt  
grub2-common-2.06-70.el9\_3.1  
grub2-common-2.06-70.el9\_3.2  
grub2-common-2.06-70.el9\_3.1  
grub2-common-2.06-70.el9\_3.2

and the debug output:

- grub2-common-2.06-70.el9\_3.1
- grub2-common-2.06-70.el9\_3.2

As per yum, the update package is grub2-common- **2.06-70.el9\_3.2** :

grub2-common noarch 1: **2.06-70.el9\_3.2**

Here’s the playbook (and thanks responders to my post for helping me get this far):

---

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [February 12, 2024, 8:06pm UTC](https://forum.ansible.com/t/another-report-creation-problem/38653/15 "2024-02-12T20:06:16Z")

</div>

I hope i don’t upset the list if i give this a bump, as i’d really like to get a solution. Please see my previous post above.
