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 latest image selection incorrect #601

Closed
megrehncitrix opened this issue Aug 17, 2021 · 7 comments
Closed

azure_rm_virtualmachine latest image selection incorrect #601

megrehncitrix opened this issue Aug 17, 2021 · 7 comments
Labels
bug Something isn't working has_pr PR fixes have been made medium_priority Medium priority

Comments

@megrehncitrix
Copy link

SUMMARY

In latest azcollection module azure_rm_virtualmachine selects an incorrect latest marketplace image.
The the selection logic assumes that the image list is returned in correct order with latest image as last of the list, this is not the case for some skus and the logic should be updated to retrieve the image flagged as latest, and not rely on an ordered list: https://github.com/ansible-collections/azure/blob/dev/plugins/modules/azure_rm_virtualmachine.py#L1973

Affects sku for generation 1 vm Server 2016:
"publisher": "MicrosoftWindowsServer", "offer": "WindowsServer", "sku": "2016-Datacenter"

ISSUE TYPE
  • Bug Report
COMPONENT NAME

azure_rm_virtualmachine

ANSIBLE VERSION
ansible 2.10.8
  python version = 3.6.8 (default, Nov 16 2020, 16:55:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
COLLECTION VERSION
Collection         Version
------------------ -------
azure.azcollection 1.5.0
STEPS TO REPRODUCE

Call the module for affected marketplace image: "publisher": "MicrosoftWindowsServer", "offer": "WindowsServer", "sku": "2016-Datacenter"
pass values for below:

- name: Create a Windows Virtual Machine
  azure_rm_virtualmachine:
    resource_group: "{{ resource_group }}"
    name: "{{ name }}"
    admin_username: "{{ admin_username }}"
    admin_password: "{{ admin_password }}"
    image:
      offer: WindowsServer
      publisher: MicrosoftWindowsServer
      sku: "2016-Datacenter"
      version: latest

EXPECTED RESULTS

This should create a vm with the latest image for the sku , which is 14393.4583.2108010852 today.

ACTUAL RESULTS

VM is created with the image version of 2016.127.20190416 an old version for sku "2016-Datacenter"

As a temporary workaround, we are pulling the latest marketplace image version from the Azure API before calling the module. Example: az vm image show --location eastus --urn MicrosoftWindowsServer:WindowsServer:2016-Datacenter:latest

@Fred-sun
Copy link
Collaborator

@megrehncitrix I executed your Playbook and the latest image you created should be 2016.127.20190416 for I(SKU = 2016-datacenter). After you log in to the system, the ver of the system is Microsoft Windows [Version 10.0.14393]. Thank you very much!

image

@Fred-sun Fred-sun added medium_priority Medium priority work in In trying to solve, or in working with contributors labels Aug 18, 2021
@megrehncitrix
Copy link
Author

Hi @Fred-sun Version 10.0.14393 is the Windows version, that's correct. But you'll notice that the image hasn't had updates applied since 2019 on marketplace image version 2016.127.20190416. The correct latest image is 14393.4583.2108010852 which has had updates applied this month.

@Fred-sun
Copy link
Collaborator

@megrehncitrix I am very sorry for the trouble caused to you. After reviewing the code logic, I have no way to directly obtain the image of the latest version. What I got was a list of image versions, so I cannot directly determine which version is the latest. So there's no way to fix it yet. I suggest you do that first? Thank you very much!

- name: Create a Windows Virtual Machine
  azure_rm_virtualmachine:
    resource_group: "{{ resource_group }}"
    name: "{{ name }}"
    admin_username: "{{ admin_username }}"
    admin_password: "{{ admin_password }}"
    image:
      offer: WindowsServer
      publisher: MicrosoftWindowsServer
      sku: "2016-Datacenter"
      version: 14393.4583.2108010852

@Fred-sun Fred-sun added the bug Something isn't working label Aug 19, 2021
@megrehncitrix
Copy link
Author

megrehncitrix commented Aug 19, 2021

Thanks @Fred-sun It may be as easy as just cleaning up the get_marketplace_image_version() function to always pass the provided version and return a single value. I'm not able to find the api docs that would confirm the same rest endpoint will return the flagged latest when provided the string latest but that seems to be how it works... basically, there's no reason to pull a full list of images and determine the latest if the api does that for you on latest.

@xuzhang3
Copy link
Collaborator

@megrehncitrix #606 will fix this issue.

@Fred-sun Fred-sun added has_pr PR fixes have been made and removed work in In trying to solve, or in working with contributors labels Aug 20, 2021
@Fred-sun
Copy link
Collaborator

fixes by #606

@davidgarvey
Copy link

az vm image show --location canadacentral --urn MicrosoftWindowsServer:WindowsServer:2016-Datacenter:latest |python -c 'import json,sys;obj=json.load(sys.stdin);print obj["name"];'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has_pr PR fixes have been made medium_priority Medium priority
Projects
None yet
Development

No branches or pull requests

4 participants