ansible-collections / azure

Development area for Azure Collections
https://galaxy.ansible.com/azure/azcollection
GNU General Public License v3.0
247 stars 330 forks source link

AttributeError: 'VirtualMachine' object has no attribute 'validate' #1168

Closed barbacbd closed 1 year ago

barbacbd commented 1 year ago
SUMMARY

Attempting to create azure virtual machines but the creation is running into

The full traceback is:
Traceback (most recent call last):
  File "/home/bbarbach/.ansible/tmp/ansible-tmp-1684886080.3735435-1355952-51169583375824/AnsiballZ_azure_rm_virtualmachine_info.py", line 107, in <module>
    _ansiballz_main()
  File "/home/bbarbach/.ansible/tmp/ansible-tmp-1684886080.3735435-1355952-51169583375824/AnsiballZ_azure_rm_virtualmachine_info.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/bbarbach/.ansible/tmp/ansible-tmp-1684886080.3735435-1355952-51169583375824/AnsiballZ_azure_rm_virtualmachine_info.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.azure.azcollection.plugins.modules.azure_rm_virtualmachine_info', init_globals=dict(_module_fqn='ansible_collections.azure.azcollection.plugins.modules.azure_rm_virtualmachine_info', _modlib_path=modlib_path),
  File "/usr/lib64/python3.9/runpy.py", line 210, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib64/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py", line 542, in <module>
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py", line 538, in main
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py", line 350, in __init__
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py", line 472, in __init__
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py", line 368, in exec_module
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py", line 396, in list_items_by_resourcegroup
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py", line 420, in get_vm
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py", line 432, in serialize_vm
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py", line 633, in serialize_obj
  File "/home/bbarbach/dev/oi-dev/ansible-venv/lib64/python3.9/site-packages/msrest/serialization.py", line 628, in body
    errors = _recursive_validate(data_type, data_type, data)
  File "/home/bbarbach/dev/oi-dev/ansible-venv/lib64/python3.9/site-packages/msrest/serialization.py", line 160, in _recursive_validate
    return data.validate()
AttributeError: 'VirtualMachine' object has no attribute 'validate'
ISSUE TYPE
COMPONENT NAME

azure_rm_virtualmachine.py

ANSIBLE VERSION
  config file = None
  configured module search path = ['/home/bbarbach/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/bbarbach/dev/oi-dev/ansible-venv/lib64/python3.9/site-packages/ansible
  ansible collection location = /home/bbarbach/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/bbarbach/dev/oi-dev/ansible-venv/bin/ansible
  python version = 3.9.6 (default, Aug 11 2021, 06:39:25) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)] (/home/bbarbach/dev/oi-dev/ansible-venv/bin/python3.9)
  jinja version = 3.1.2
  libyaml = True

Built off of devel branch

COLLECTION VERSION
Collection         Version
------------------ -------
azure.azcollection 1.15.0 
CONFIGURATION
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly
changing source of code and can become unstable at any point.
CONFIG_FILE() = None
OS / ENVIRONMENT

RHEL 8.7

STEPS TO REPRODUCE
- name: Retrieve platform VM list
  azure.azcollection.azure_rm_virtualmachine_info:
    resource_group: "{{ azure_resource_group }}"
  register: azure_vms
  run_once: true
EXPECTED RESULTS

Find the azure vms given the resource search values

ACTUAL RESULTS
The full traceback is:
Traceback (most recent call last):
  File "/home/bbarbach/.ansible/tmp/ansible-tmp-1684886080.3735435-1355952-51169583375824/AnsiballZ_azure_rm_virtualmachine_info.py", line 107, in <module>
    _ansiballz_main()
  File "/home/bbarbach/.ansible/tmp/ansible-tmp-1684886080.3735435-1355952-51169583375824/AnsiballZ_azure_rm_virtualmachine_info.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/bbarbach/.ansible/tmp/ansible-tmp-1684886080.3735435-1355952-51169583375824/AnsiballZ_azure_rm_virtualmachine_info.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.azure.azcollection.plugins.modules.azure_rm_virtualmachine_info', init_globals=dict(_module_fqn='ansible_collections.azure.azcollection.plugins.modules.azure_rm_virtualmachine_info', _modlib_path=modlib_path),
  File "/usr/lib64/python3.9/runpy.py", line 210, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib64/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py", line 542, in <module>
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py", line 538, in main
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py", line 350, in __init__
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py", line 472, in __init__
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py", line 368, in exec_module
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py", line 396, in list_items_by_resourcegroup
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py", line 420, in get_vm
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py", line 432, in serialize_vm
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py", line 633, in serialize_obj
  File "/home/bbarbach/dev/oi-dev/ansible-venv/lib64/python3.9/site-packages/msrest/serialization.py", line 628, in body
    errors = _recursive_validate(data_type, data_type, data)
  File "/home/bbarbach/dev/oi-dev/ansible-venv/lib64/python3.9/site-packages/msrest/serialization.py", line 160, in _recursive_validate
    return data.validate()
AttributeError: 'VirtualMachine' object has no attribute 'validate'
fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/bbarbach/.ansible/tmp/ansible-tmp-1684886080.3735435-1355952-51169583375824/AnsiballZ_azure_rm_virtualmachine_info.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/bbarbach/.ansible/tmp/ansible-tmp-1684886080.3735435-1355952-51169583375824/AnsiballZ_azure_rm_virtualmachine_info.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/bbarbach/.ansible/tmp/ansible-tmp-1684886080.3735435-1355952-51169583375824/AnsiballZ_azure_rm_virtualmachine_info.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.azure.azcollection.plugins.modules.azure_rm_virtualmachine_info', init_globals=dict(_module_fqn='ansible_collections.azure.azcollection.plugins.modules.azure_rm_virtualmachine_info', _modlib_path=modlib_path),\n  File \"/usr/lib64/python3.9/runpy.py\", line 210, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib64/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py\", line 542, in <module>\n  File \"/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py\", line 538, in main\n  File \"/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py\", line 350, in __init__\n  File \"/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py\", line 472, in __init__\n  File \"/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py\", line 368, in exec_module\n  File \"/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py\", line 396, in list_items_by_resourcegroup\n  File \"/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py\", line 420, in get_vm\n  File \"/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine_info.py\", line 432, in serialize_vm\n  File \"/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload_7n_p21_0/ansible_azure.azcollection.azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py\", line 633, in serialize_obj\n  File \"/home/bbarbach/dev/oi-dev/ansible-venv/lib64/python3.9/site-packages/msrest/serialization.py\", line 628, in body\n    errors = _recursive_validate(data_type, data_type, data)\n  File \"/home/bbarbach/dev/oi-dev/ansible-venv/lib64/python3.9/site-packages/msrest/serialization.py\", line 160, in _recursive_validate\n    return data.validate()\nAttributeError: 'VirtualMachine' object has no attribute 'validate'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}
Fred-sun commented 1 year ago

@barbacbd This problem is very strange and cannot be reproduced locally. Could you please help to provide how to reproduce this problem? In addition, could you please provide the VM configuration information you need in the list? In order to better solve this problem, thank you!

barbacbd commented 1 year ago

@Fred-sun Some background information might help =). I created some RHCOS nodes using the openshift installer. I wanted to grab the node information that I created and copy those and create new RHEL nodes. Really the only information that I need right now is the ID of the VM(s).

The easiest way to reproduce this is to create a VM in azure, then from the ansible task snippet above you can grab the resource group name of the vm and pass it to the task as {{ azure_resource_group }}. From this I should be able to get a list of all VMs matching that resource group.

Is this enough information to go on?

Fred-sun commented 1 year ago

@barbacbd I did the same, but got the VM information right. Thanks!

Fred-sun commented 1 year ago

@barbacbd Could you please provide the version information of all the packages installed(such as "pip3 list")? Thanks!

barbacbd commented 1 year ago
Package                               Version
------------------------------------- -----------
-zure-mgmt-compute                    26.1.0
adal                                  1.2.7
ansible-compat                        2.2.7
ansible-core                          2.16.0.dev0
antlr4-python3-runtime                4.9.3
applicationinsights                   0.11.10
argcomplete                           1.12.3
arrow                                 1.2.3
attrs                                 22.2.0
azure-appconfiguration                1.1.1
azure-cli-core                        2.34.0
azure-cli-telemetry                   1.0.6
azure-common                          1.1.11
azure-containerregistry               1.0.0
azure-core                            1.26.4
azure-cosmos                          3.2.0
azure-data-tables                     12.4.0
azure-graphrbac                       0.60.0
azure-identity                        1.7.0
azure-keyvault                        1.1.0
azure-keyvault-certificates           4.7.0
azure-loganalytics                    0.1.1
azure-mgmt-advisor                    9.0.0
azure-mgmt-apimanagement              3.0.0
azure-mgmt-authorization              3.0.0
azure-mgmt-automation                 1.0.0
azure-mgmt-batch                      5.0.1
azure-mgmt-batchai                    7.0.0b1
azure-mgmt-billing                    6.0.0
azure-mgmt-botservice                 2.0.0
azure-mgmt-cdn                        11.0.0
azure-mgmt-compute                    29.1.0
azure-mgmt-containerinstance          10.1.0
azure-mgmt-containerregistry          9.1.0
azure-mgmt-containerservice           20.0.0
azure-mgmt-core                       1.3.0
azure-mgmt-cosmosdb                   6.4.0
azure-mgmt-databoxedge                1.0.0
azure-mgmt-datafactory                2.0.0
azure-mgmt-datalake-analytics         0.2.1
azure-mgmt-datalake-nspkg             3.0.1
azure-mgmt-datalake-store             1.0.0
azure-mgmt-devtestlabs                3.0.0
azure-mgmt-dns                        8.0.0
azure-mgmt-eventhub                   10.1.0
azure-mgmt-extendedlocation           1.0.0b2
azure-mgmt-hdinsight                  9.0.0
azure-mgmt-iothub                     2.3.0
azure-mgmt-iothubprovisioningservices 1.1.0
azure-mgmt-keyvault                   10.0.0
azure-mgmt-loganalytics               12.0.0
azure-mgmt-managedservices            1.0.0
azure-mgmt-managementgroups           0.2.0
azure-mgmt-marketplaceordering        1.1.0
azure-mgmt-media                      9.0.0
azure-mgmt-monitor                    3.0.0
azure-mgmt-network                    19.1.0
azure-mgmt-notificationhubs           7.0.0
azure-mgmt-nspkg                      2.0.0
azure-mgmt-privatedns                 1.0.0
azure-mgmt-rdbms                      10.2.0b8
azure-mgmt-recoveryservices           2.2.0
azure-mgmt-recoveryservicesbackup     3.0.0
azure-mgmt-redhatopenshift            1.2.0
azure-mgmt-redis                      13.0.0
azure-mgmt-resource                   21.1.0
azure-mgmt-search                     8.0.0
azure-mgmt-servicebus                 7.1.0
azure-mgmt-servicefabric              1.0.0
azure-mgmt-signalr                    1.1.0
azure-mgmt-sql                        3.0.1
azure-mgmt-storage                    21.0.0
azure-mgmt-trafficmanager             1.0.0
azure-mgmt-web                        6.1.0
azure-nspkg                           2.0.0
azure-storage-blob                    12.11.0
azure-storage-common                  1.4.2
azure-synapse-managedprivateendpoints 0.4.0
azure-synapse-spark                   0.2.0
bcrypt                                4.0.1
binaryornot                           0.4.4
boto3                                 1.26.66
botocore                              1.29.66
cachetools                            5.3.0
certifi                               2022.12.7
cffi                                  1.15.1
chardet                               3.0.4
charset-normalizer                    3.0.1
click                                 8.1.3
click-help-colors                     0.9.1
colorama                              0.4.6
cookiecutter                          2.1.1
cryptography                          39.0.0
Deprecated                            1.2.13
distro                                1.8.0
enrich                                1.2.7
fabric                                2.7.1
google-api-core                       2.11.0
google-api-python-client              2.74.0
google-auth                           2.16.0
google-auth-httplib2                  0.1.0
googleapis-common-protos              1.58.0
httplib2                              0.21.0
humanfriendly                         10.0
idna                                  3.4
importlib-resources                   5.0.7
invoke                                1.7.3
isodate                               0.6.1
javaproperties                        0.5.2
Jinja2                                3.1.2
jinja2-ansible-filters                1.3.2
jinja2-time                           0.2.0
jmespath                              1.0.1
jsondiff                              2.0.0
jsonschema                            4.17.3
knack                                 0.9.0
markdown-it-py                        2.1.0
MarkupSafe                            2.1.2
mdurl                                 0.1.2
molecule                              4.0.4
molecule-gce                          1.0.0
msal                                  1.20.0
msal-extensions                       0.3.1
msrest                                0.7.1
msrestazure                           0.6.4
ntlm-auth                             1.5.0
oauthlib                              3.2.2
packaging                             21.3
paramiko                              2.12.0
pathlib2                              2.3.7.post1
pip                                   20.2.4
pkginfo                               1.9.6
pluggy                                1.0.0
portalocker                           1.7.1
protobuf                              4.21.12
psutil                                5.9.4
pyasn1                                0.4.8
pyasn1-modules                        0.2.8
pycparser                             2.21
pycryptodome                          3.17
PyGithub                              1.58.0
Pygments                              2.14.0
PyJWT                                 2.6.0
PyMySQL                               1.0.2
PyNaCl                                1.5.0
pyOpenSSL                             23.0.0
pyparsing                             3.0.9
pyrsistent                            0.19.3
python-dateutil                       2.8.2
python-slugify                        8.0.0
pywinrm                               0.4.3
PyYAML                                6.0
requests                              2.28.2
requests-ntlm                         1.1.0
requests-oauthlib                     1.3.1
resolvelib                            0.8.1
rich                                  13.3.1
rsa                                   4.9
s3transfer                            0.6.0
scp                                   0.13.6
semver                                2.13.0
setuptools                            50.3.2
six                                   1.16.0
sshtunnel                             0.1.5
subprocess-tee                        0.4.1
tabulate                              0.9.0
text-unidecode                        1.3
typing-extensions                     4.5.0
uritemplate                           4.1.1
urllib3                               1.26.14
urllib3-secure-extra                  0.1.0
websocket-client                      1.3.3
wrapt                                 1.15.0
xmltodict                             0.13.0

I installed the azure packages from the list in .ansible/collections/ansible_collections/azure/azcollection. I just noticed the first package in the list seems incorrect. The name certainly looks corrupted.

barbacbd commented 1 year ago

@Fred-sun based on the comment above I see some other info. The requirements list has the version listed that looks corrupted, but the version installed is 29.x.x. I wonder if this caused some different packages to be installed that don't match.

Fred-sun commented 1 year ago

@barbacbd Yes, there is a problem with the version you are using, it is recommended that you install the version specified by requirement-azure.txt. Please try the following method, thank you!


Reinstall azure-mgmt-compute to v26.1.0
sudo pip3 install azure-mgmt-compute==26.1.0 -I