Bug 1653743

Summary: [RFE] ansible modules facts - return nested information for all elements with 'href' attribute
Product: Red Hat Enterprise Virtualization Manager Reporter: Lucie Leistnerova <lleistne>
Component: ansibleAssignee: Martin Necas <mnecas>
Status: CLOSED CURRENTRELEASE QA Contact: Pavol Brilla <pbrilla>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 4.3.0CC: lsvaty, mgoldboi, mperina, omachace, pbrilla
Target Milestone: ovirt-4.3.7Keywords: FutureFeature, ZStream
Target Release: ---Flags: lleistne: testing_plan_complete?
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: ansible-2.8.4-1.el7ae Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-01-09 13:25:51 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Infra RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Lucie Leistnerova 2018-11-27 14:28:05 UTC
Description of problem:
Parameter fetch_nested in facts modules (e.g. ovirt_vm_facts) returns data only for <link> elements. But there are also <template>, <storage_domain> and other elements that could load data too.

for example in VM API call:

        <lease>
            <storage_domain href="/ovirt-engine/api/storagedomains/b1d7018b-14b1-4766-b390-5a95974ec38b" id="b1d7018b-14b1-4766-b390-5a95974ec38b"/>
        </lease>
...
        <cluster href="/ovirt-engine/api/clusters/00000002-0002-0002-0002-00000000017a" id="00000002-0002-0002-0002-00000000017a"/>
        <cpu_profile href="/ovirt-engine/api/cpuprofiles/58a16ddd-0017-0195-0176-0000000000d9" id="58a16ddd-0017-0195-0176-0000000000d9"/>
        <quota id="58a16e35-03c4-03d0-0104-0000000001ce"/>
        <next_run_configuration_exists>false</next_run_configuration_exists>
        <numa_tune_mode>interleave</numa_tune_mode>
        <status>down</status>
        <stop_time>2018-10-31T09:18:53.411+01:00</stop_time>
        <original_template href="/ovirt-engine/api/templates/00000000-0000-0000-0000-000000000000" id="00000000-0000-0000-0000-000000000000"/>
        <template href="/ovirt-engine/api/templates/00000000-0000-0000-0000-000000000000" id="00000000-0000-0000-0000-000000000000"/>

Comment 3 Lucie Leistnerova 2019-05-29 14:13:49 UTC
Direct elements works, e.g. disks:
<quota href="/ovirt-engine/api/datacenters/87bc2e30-f3b1-11e8-aa7d-001a4a013f36/quotas/96f2a2e4-f3b1-11e8-82b6-001a4a013f36" id="96f2a2e4-f3b1-11e8-82b6-001a4a013f36"/>
-->
"quota": {
                "href": "/ovirt-engine/api/datacenters/87bc2e30-f3b1-11e8-aa7d-001a4a013f36/quotas/96f2a2e4-f3b1-11e8-82b6-001a4a013f36",
                "id": "96f2a2e4-f3b1-11e8-82b6-001a4a013f36",
                "name": "Default"
            },

But when the element is in a list or other element, it doesn't work, e.g. in disks:

        <storage_domains>
            <storage_domain href="/ovirt-engine/api/storagedomains/82ceb4c9-e844-4fc7-b0ff-559052e6301f" id="82ceb4c9-e844-4fc7-b0ff-559052e6301f"/>
        </storage_domains>
-->
            "storage_domains": [
                {
                    "href": "/ovirt-engine/api/storagedomains/82ceb4c9-e844-4fc7-b0ff-559052e6301f",
                    "id": "82ceb4c9-e844-4fc7-b0ff-559052e6301f"
                }
            ],

or template:

        <version>
            <version_name>base version</version_name>
            <version_number>1</version_number>
            <base_template href="/ovirt-engine/api/templates/264640fc-1b51-4263-995b-47e3e9dd3c8f" id="264640fc-1b51-4263-995b-47e3e9dd3c8f"/>
        </version>
-->
            "version": {
                "base_template": {
                    "href": "/ovirt-engine/api/templates/264640fc-1b51-4263-995b-47e3e9dd3c8f",
                    "id": "264640fc-1b51-4263-995b-47e3e9dd3c8f"
                },
                "version_name": "base version",
                "version_number": 1
            },

Tested in ansible-2.8.0-0.9.rc3.el7ae.noarch

Comment 4 Lucie Leistnerova 2019-06-07 08:26:49 UTC
One other thing I've found, ovirt_host_facts returns more on <cluster> than needed when not nested.

      ovirt_host_facts:
        auth: "{{ ovirt_auth }}"
        pattern: "name=vhost*"
        fetch_nested: True
        nested_attributes:
          - name

returns correctly:

            "cluster": {
                "href": "/ovirt-engine/api/clusters/87c0c65c-f3b1-11e8-9209-001a4a013f36",
                "id": "87c0c65c-f3b1-11e8-9209-001a4a013f36",
                "name": "Default"
            },

but with fetch_nested: False returns all information on the cluster

"cluster": {
                "affinity_groups": [],
                "ballooning_enabled": false,
                "comment": "",
                "cpu": {
                    "architecture": "x86_64",
                    "type": "Intel Westmere Family"
                },
....

But in module ovirt_vm_facts it works as expected.

Comment 5 Ondra Machacek 2019-06-11 11:15:47 UTC
We fetch this info in ovirt_host_facts, so we are able to compare cluster version and filter it. This is different issue only in ovirt_host_facts. Can you please open an issue for that module.

Comment 6 Lucie Leistnerova 2019-06-11 13:12:18 UTC
Done - BZ 1719303

Comment 7 Sandro Bonazzola 2019-07-30 07:35:46 UTC
ansible-2.8.3 has been released, please check this bug is fixed there.

Comment 9 Sandro Bonazzola 2019-08-23 13:31:26 UTC
Can we get this verified?

Comment 10 Pavol Brilla 2019-08-26 10:51:07 UTC
Working for storage_domains in disks, but for base_template in element version in template still doesn't return name of template 

ansible localhost -m ovirt_template_facts -a 'pattern="name=*" fetch_nested=True nested_attributes=name'
......
                "version": {
                    "base_template": {
                        "href": "/ovirt-engine/api/templates/154f10b7-de72-4b0b-87cf-54a52d7ad035", 
                        "id": "154f10b7-de72-4b0b-87cf-54a52d7ad035"
                    }, 
......

VS

<template href="/ovirt-engine/api/templates/154f10b7-de72-4b0b-87cf-54a52d7ad035" id="154f10b7-de72-4b0b-87cf-54a52d7ad035">
.....
    <name>golden_template_rhel7.7</name>



# ansible --version
ansible 2.8.4

Comment 11 Ondra Machacek 2019-09-05 11:49:46 UTC
(In reply to Pavol Brilla from comment #10)
> Working for storage_domains in disks, but for base_template in element
> version in template still doesn't return name of template 
> 
> ansible localhost -m ovirt_template_facts -a 'pattern="name=*"
> fetch_nested=True nested_attributes=name'
> ......
>                 "version": {
>                     "base_template": {
>                         "href":
> "/ovirt-engine/api/templates/154f10b7-de72-4b0b-87cf-54a52d7ad035", 
>                         "id": "154f10b7-de72-4b0b-87cf-54a52d7ad035"
>                     }, 
> ......
> 
> VS
> 
> <template
> href="/ovirt-engine/api/templates/154f10b7-de72-4b0b-87cf-54a52d7ad035"
> id="154f10b7-de72-4b0b-87cf-54a52d7ad035">
> .....
>     <name>golden_template_rhel7.7</name>
> 
> 
> 
> # ansible --version
> ansible 2.8.4

Going over each nested attribute attributes and checking if it's a link would bring much bigger time complexity, for no value IMHO. We should document that by default we go only over first level attributes, not any other level of attribute and maybe add parameter which enables going deeper, but I would close this bug, and open new one to track this. Moving back to ON_QA.

Comment 12 Pavol Brilla 2019-11-04 08:11:02 UTC
Issue opened for clarification: https://github.com/ansible/ansible/issues/63127

As previously stated other cases verified

Comment 13 Sandro Bonazzola 2020-01-09 13:25:51 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2019:2543