Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azure_rm_virtualmachine is throwing KeyError: 'os_profile' for some VMs #1274

Closed
vijayreddiar opened this issue Sep 27, 2023 · 7 comments · Fixed by #1301
Closed

azure_rm_virtualmachine is throwing KeyError: 'os_profile' for some VMs #1274

vijayreddiar opened this issue Sep 27, 2023 · 7 comments · Fixed by #1301
Assignees
Labels
bug Something isn't working

Comments

@vijayreddiar
Copy link

SUMMARY

While attempting to perform any operation on a VM like stop, start or modify, it is failing with error KeyError: 'os_profile' for only some of the VMs where os_profile is not fetched under ansible_facts, but the same was working till we initiated a project sync in AWX this week. So unsure from which version of azure.azcollection resulted to throw this error.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

azure_rm_virtualmachine

ANSIBLE VERSION
ansible [core 2.15.4]
  config file = None
  configured module search path = ['/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.17 (main, Aug  9 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
# /usr/share/ansible/collections/ansible_collections
Collection         Version
------------------ -------
azure.azcollection 1.18.1
CONFIGURATION
CONFIG_FILE() = None
OS / ENVIRONMENT

AWX on K3S

# cat /etc/os-release
NAME="Red Hat Enterprise Linux"
VERSION="8.8 (Ootpa)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="8.8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Red Hat Enterprise Linux 8.8 (Ootpa)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:8::baseos"
HOME_URL="https://www.redhat.com/"
DOCUMENTATION_URL="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 8"
REDHAT_BUGZILLA_PRODUCT_VERSION=8.8
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="8.8"
STEPS TO REPRODUCE

Execute below task within a playbook after setting the right variables

- name: Stop Azure VM
  azure.azcollection.azure_rm_virtualmachine:
    auth_source: "{{ azure_auth_source }}"
    profile: "{{ azure_profile }}"
    resource_group: "{{ azure_resource_group }}"
    name: "{{ vm_name }}"
    started: false
    allocated: "{{ is_allocated }}"
EXPECTED RESULTS

The Azure VM should be stopped.

ACTUAL RESULTS

The VM is not stopped and throwing the error as below.

TASK [provision_ops_stop_vm : Stop Azure VM] ***********************************
task path: /runner/project/roles/provision_ops_stop_vm/tasks/azure_stop_vm.yml:2
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: 1000
<localhost> EXEC /bin/sh -c 'echo ~1000 && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /runner/.ansible/tmp `"&& mkdir "` echo /runner/.ansible/tmp/ansible-tmp-1695797383.8451161-39-228019381031999 `" && echo ansible-tmp-1695797383.8451161-39-228019381031999="` echo /runner/.ansible/tmp/ansible-tmp-1695797383.8451161-39-228019381031999 `" ) && sleep 0'
Using module file /runner/requirements_collections/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine.py
<localhost> PUT /runner/.ansible/tmp/ansible-local-16hnuyfpl1/tmpmakqnxvm TO /runner/.ansible/tmp/ansible-tmp-1695797383.8451161-39-228019381031999/AnsiballZ_azure_rm_virtualmachine.py
<localhost> EXEC /bin/sh -c 'chmod u+x /runner/.ansible/tmp/ansible-tmp-1695797383.8451161-39-228019381031999/ /runner/.ansible/tmp/ansible-tmp-1695797383.8451161-39-228019381031999/AnsiballZ_azure_rm_virtualmachine.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python3 /runner/.ansible/tmp/ansible-tmp-1695797383.8451161-39-228019381031999/AnsiballZ_azure_rm_virtualmachine.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /runner/.ansible/tmp/ansible-tmp-1695797383.8451161-39-228019381031999/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/runner/.ansible/tmp/ansible-tmp-1695797383.8451161-39-228019381031999/AnsiballZ_azure_rm_virtualmachine.py", line 107, in <module>
    _ansiballz_main()
  File "/runner/.ansible/tmp/ansible-tmp-1695797383.8451161-39-228019381031999/AnsiballZ_azure_rm_virtualmachine.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/runner/.ansible/tmp/ansible-tmp-1695797383.8451161-39-228019381031999/AnsiballZ_azure_rm_virtualmachine.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.azure.azcollection.plugins.modules.azure_rm_virtualmachine', init_globals=dict(_module_fqn='ansible_collections.azure.azcollection.plugins.modules.azure_rm_virtualmachine', _modlib_path=modlib_path),
  File "/usr/lib64/python3.9/runpy.py", line 225, 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_payload_xsc2vthv/ansible_azure.azcollection.azure_rm_virtualmachine_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine.py", line 2711, in <module>
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_payload_xsc2vthv/ansible_azure.azcollection.azure_rm_virtualmachine_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine.py", line 2707, in main
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_payload_xsc2vthv/ansible_azure.azcollection.azure_rm_virtualmachine_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine.py", line 1136, in __init__
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_payload_xsc2vthv/ansible_azure.azcollection.azure_rm_virtualmachine_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py", line 461, in __init__
  File "/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_payload_xsc2vthv/ansible_azure.azcollection.azure_rm_virtualmachine_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine.py", line 1486, in exec_module
KeyError: 'os_profile'
fatal: [testvm -> localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\\n  File \\"/runner/.ansible/tmp/ansible-tmp-1695797383.8451161-39-228019381031999/AnsiballZ_azure_rm_virtualmachine.py\\", line 107, in <module>\\n    _ansiballz_main()\\n  File \\"/runner/.ansible/tmp/ansible-tmp-1695797383.8451161-39-228019381031999/AnsiballZ_azure_rm_virtualmachine.py\\", line 99, in _ansiballz_main\\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\\n  File \\"/runner/.ansible/tmp/ansible-tmp-1695797383.8451161-39-228019381031999/AnsiballZ_azure_rm_virtualmachine.py\\", line 47, in invoke_module\\n    runpy.run_module(mod_name='ansible_collections.azure.azcollection.plugins.modules.azure_rm_virtualmachine', init_globals=dict(_module_fqn='ansible_collections.azure.azcollection.plugins.modules.azure_rm_virtualmachine', _modlib_path=modlib_path),\\n  File \\"/usr/lib64/python3.9/runpy.py\\", line 225, 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_payload_xsc2vthv/ansible_azure.azcollection.azure_rm_virtualmachine_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine.py\\", line 2711, in <module>\\n  File \\"/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_payload_xsc2vthv/ansible_azure.azcollection.azure_rm_virtualmachine_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine.py\\", line 2707, in main\\n  File \\"/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_payload_xsc2vthv/ansible_azure.azcollection.azure_rm_virtualmachine_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine.py\\", line 1136, in __init__\\n  File \\"/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_payload_xsc2vthv/ansible_azure.azcollection.azure_rm_virtualmachine_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py\\", line 461, in __init__\\n  File \\"/tmp/ansible_azure.azcollection.azure_rm_virtualmachine_payload_xsc2vthv/ansible_azure.azcollection.azure_rm_virtualmachine_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine.py\\", line 1486, in exec_module\\nKeyError: 'os_profile'\\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\\nSee stdout/stderr for the exact error",
    "rc": 1
}
@vijayreddiar
Copy link
Author

This issue is reproducible for all VMs which is created using the snapshot of OS disk of another VM. JSON view of such VMs in Azure will look like below and there will not be any osProfile properties for such VMs

"storageProfile": {
            "osDisk": {
                "osType": "Windows",
                "name": "xxxxxxxxxxxxxxxxxx",
                "createOption": "Attach"

The stop/start of same configuration VMs were working earlier, hence this issue is happening only for the recent version of azure.azcollection

@vijayreddiar
Copy link
Author

We are able to use this module upto v1.17.0 and this issue is occurring only from v1.18.0 onwards

@aleixap88
Copy link

I am trying to generate a custom EE to be able to manage servers in Azure using version 1.17.0 of azure.azcollection and I am getting the same error of "KeyError: 'os_profile'".

LOG on EE creation that indicates the installation of the azcollection versuib 1.17.0:

#14 28.36 Downloading https://galaxy.ansible.com/api/v3/plugin/ansible/content/published/collections/artifacts/azure-azcollection-1.17.0.tar.gz to /root/.ansible/tmp/ansible-local-1sfa302y5/tmpfri6t8c1/azure-azcollection-1.17.0-01opqap1
#14 28.36 Installing 'azure.azcollection:1.17.0' to '/usr/share/ansible/collections/ansible_collections/azure/azcollection'
#14 28.36 azure.azcollection:1.17.0 was installed `successfully`

The error that appears to me is
Traceback (most recent call last):\n File \"/runner/.ansible/tmp/ansible-tmp-1696500571.0504029-50-33674198612736/AnsiballZ_azure_rm_virtualmachine.py\", line 107, in <module>\n _ansiballz_main()\n File \"/runner/.ansible/tmp/ansible-tmp-1696500571.0504029-50-33674198612736/AnsiballZ_azure_rm_virtualmachine.py\", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/runner/.ansible/tmp/ansible-tmp-1696500571.0504029-50-33674198612736/AnsiballZ_azure_rm_virtualmachine.py\", line 47, in invoke_module\n runpy.run_module(mod_name='ansible_collections.azure.azcollection.plugins.modules.azure_rm_virtualmachine', init_globals=dict(_module_fqn='ansible_collections.azure.azcollection.plugins.modules.azure_rm_virtualmachine', _modlib_path=modlib_path),\n File \"<frozen runpy>\", line 226, in run_module\n File \"<frozen runpy>\", line 98, in _run_module_code\n File \"<frozen runpy>\", line 88, in _run_code\n File \"/tmp/ansible_azure_rm_virtualmachine_payload_1yg26opt/ansible_azure_rm_virtualmachine_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine.py\", line 2711, in <module>\n File \"/tmp/ansible_azure_rm_virtualmachine_payload_1yg26opt/ansible_azure_rm_virtualmachine_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine.py\", line 2707, in main\n File \"/tmp/ansible_azure_rm_virtualmachine_payload_1yg26opt/ansible_azure_rm_virtualmachine_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine.py\", line 1136, in __init__\n File \"/tmp/ansible_azure_rm_virtualmachine_payload_1yg26opt/ansible_azure_rm_virtualmachine_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py\", line 461, in __init__\n File \"/tmp/ansible_azure_rm_virtualmachine_payload_1yg26opt/ansible_azure_rm_virtualmachine_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachine.py\", line 1486, in exec_module\nKeyError: 'os_profile'\n

How can avoid this error?

@vijayreddiar
Copy link
Author

vijayreddiar commented Oct 5, 2023

I have below version reference in collections/requirements.yml and then sync the project in AWX configured with default AWX-EE

- name: azure.azcollection
  version: 1.17.0

So irrespective of any EE, even if its a custom one, I believe you will have to control this within playbook project folder. If the version is not specified, it will override to use the latest available version which is 1.18.1 now

@aleixap88
Copy link

I tried to build a new custom awx-EE with this collections:

#/usr/share/ansible/collections/ansible_collections
Collection         Version
------------------ -------
ansible.posix      1.5.4
ansible.windows    2.1.0
awx.awx            23.2.0
azure.azcollection 1.17.0
community.general  7.5.0

but it appears the same error "KeyError: 'os_profile'"

I don't understand why :( since at the end of August it was working correctly

@vijayreddiar
Copy link
Author

vijayreddiar commented Oct 10, 2023

Based on this article, it's a limitation in Azure. The latest version of azure.azcollection has ignored this limitation and we could understand that this ansible collection is not suitable for general usage at this moment as creating VM from existing or specialized disk is one of the common use case.

@xuzhang3 xuzhang3 added the bug Something isn't working label Oct 27, 2023
@xuzhang3 xuzhang3 self-assigned this Oct 27, 2023
@Fred-sun
Copy link
Collaborator

Fixes by #1301

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants