I am using the ovirt_snapshot_info module to obtain information about our VM snapshots. I register the output and it contains an array of values, 1 for each VM, then within that output, there’s an array of values called ovirt_snapshots (See sample below). I’m trying to get to the “description” value for each snapshot, but for the life of me, I can’t get it to work. I’d appreciate any thoughts or ideas.
That works, but it only shows the info for the first VM. There are 22 total. What I’d like to have is the VM name and list of all of that VMs snapshots, so I need to be able to traverse through the output at the VM level, then travers that VM’s ovirt_snapshots data.
TASK [Show results] ***********************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘description’ is undefined. ‘description’ is undefined\n\nThe error appears to be in ‘/root/vm_snapshot_info.yml’: line 48, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Show results\n ^ here\n”}
name: Show results
ansible.builtin.debug:
msg: “{{ item,description }}”
loop:
TASK [Show results] ***********************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘list object’ has no attribute ‘description’. ‘list object’ has no attribute ‘description’\n\nThe error appears to be in ‘/root/vm_snapshot_info.yml’: line 48, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Show results\n ^ here\n”}
Again, without the play including the “loop:” we have no idea what “item” looks like.
When you get something like the error you quoted, where it’s looking at an object (a list object by that message) and you don’t know how to reference data contained within, just take off all the other bits and have debug show you
msg: “{{ item }}”
Then work your way one level at a time until you get the expression right.
I get what you’re saying, but when I just debug print {{ item }} using the results variable, I see all of the snapshots listed. If I add in the loop and use {{ item[0] }}, I see the same information, and description is included. But when I try to add description to the output, I am told that it doesn’t exist. So I’m at the “until you get the expression right” phase, but no matter what I use, the expression isn’t right.
name: Gather VM Snapshot info
redhat.rhv.ovirt_snapshot_info:
auth: “{{ ovirt_auth }}”
vm: “{{ item }}”
register: result
with_items:
“vm1”
name: Show results
ansible.builtin.debug:
msg: “{{ item[0].description }}”
loop: