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

Support for creating VMS through community images #1759

Merged

Conversation

Fred-sun
Copy link
Collaborator

SUMMARY

Support for creating VMS through community images, try to fixes #1757

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

azure_rm_virutualmachine.py
azure_rm_virutualmachine_info.py
azure_rm_virutualmachinescaleset.py
azure_rm_virutualmachinescaleset_info.py

ADDITIONAL INFORMATION

@Fred-sun Fred-sun added ready_for_review The PR has been modified and can be reviewed and merged medium_priority Medium priority new_feature New feature requirments labels Nov 15, 2024
@arvindshmicrosoft
Copy link

@Fred-sun thank you for making these changes. I copied your changes from this PR to my local for testing with the Fedora 40 community gallery image /CommunityGalleries/fedora-5e266ba4-2250-406d-adad-5d73860d958f/Images/Fedora-Cloud-40-x64/Versions/latest. Unfortunately, it gives the following error:

fatal: [localhost]: FAILED! => {"changed": false, "msg": "Error creating or updating virtual machine myVM - (InvalidParameter) The value of parameter imageReference.publisher is invalid.\nCode: InvalidParameter\nMessage: The value of parameter imageReference.publisher is invalid.\nTarget: imageReference.publisher"}

Is it possible for you to do an actual test before finalizing this PR? It would be really appreciated. Thank you.

@Fred-sun
Copy link
Collaborator Author

Fred-sun commented Nov 20, 2024

@arvindshmicrosoft Did you not update the code of line 2217, or could you please provide the detailed error report of -vvvv? Thank you!

@arvindshmicrosoft
Copy link

@arvindshmicrosoft Did you not update the code of line 2217, or could you please provide the detailed error report of -vvvv? Thank you!

I copied the entire file over to my local, it's confirmed to be using your code. Here is the test playbook and later the output as well. Were you able to get it working successfully with any other community gallery image?

- hosts: localhost
  tasks:
  - name: Create VM with community gallery image ID
    azure_rm_virtualmachine:
      resource_group: "my-test"
      name: "community-gallery-image-vm"
      admin_username: testuser
      ssh_password_enabled: false
      managed_disk_type: Premium_LRS
      open_ports:
        - 33
      ssh_public_keys:
        - path: /home/testuser/.ssh/authorized_keys
          key_data: "<<REDACTED>>"
      vm_size: Standard_B1ms
      network_interface_names:
      - "myNIC"
      image:
        community_gallery_image_id: "/CommunityGalleries/fedora-5e266ba4-2250-406d-adad-5d73860d958f/Images/Fedora-Cloud-40-x64/Versions/latest"

Output:

TASK [Create VM with community gallery image ID] ***********************************************************************************************
task path: /home/my/workarea/ansible/test.yml:3
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: my
<127.0.0.1> EXEC /bin/sh -c 'echo ~my && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/my/.ansible/tmp `"&& mkdir "` echo /home/my/.ansible/tmp/ansible-tmp-1732076593.0191154-17074-109142360521524 `" && echo ansible-tmp-1732076593.0191154-17074-109142360521524="` echo /home/my/.ansible/tmp/ansible-tmp-1732076593.0191154-17074-109142360521524 `" ) && sleep 0'
Loading collection azure.azcollection from /home/my/.ansible/collections/ansible_collections/azure/azcollection
Using module file /home/my/workarea/ansible/library/azure_rm_virtualmachine.py
<127.0.0.1> PUT /home/my/.ansible/tmp/ansible-local-16965s5awc1gx/tmp6y1iz0fi TO /home/my/.ansible/tmp/ansible-tmp-1732076593.0191154-17074-109142360521524/AnsiballZ_azure_rm_virtualmachine.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/my/.ansible/tmp/ansible-tmp-1732076593.0191154-17074-109142360521524/ /home/my/.ansible/tmp/ansible-tmp-1732076593.0191154-17074-109142360521524/AnsiballZ_azure_rm_virtualmachine.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/home/my/env311/bin/python3.11 /home/my/.ansible/tmp/ansible-tmp-1732076593.0191154-17074-109142360521524/AnsiballZ_azure_rm_virtualmachine.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/my/.ansible/tmp/ansible-tmp-1732076593.0191154-17074-109142360521524/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
  File "/tmp/ansible_azure_rm_virtualmachine_payload_sflcc9me/ansible_azure_rm_virtualmachine_payload.zip/ansible/modules/azure_rm_virtualmachine.py", line 2904, in create_or_update_vm
    poller = self.compute_client.virtual_machines.begin_create_or_update(self.resource_group, self.name, params)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/my/env311/lib/python3.11/site-packages/azure/core/tracing/decorator.py", line 76, in wrapper_use_tracer
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/my/env311/lib/python3.11/site-packages/azure/mgmt/compute/v2021_04_01/operations/_operations.py", line 12109, in begin_create_or_update
    raw_result = self._create_or_update_initial(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/my/env311/lib/python3.11/site-packages/azure/mgmt/compute/v2021_04_01/operations/_operations.py", line 12007, in _create_or_update_initial
    raise HttpResponseError(response=response, error_format=ARMErrorFormat)
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "accept_terms": false,
            "ad_user": null,
            "additional_capabilities": null,
            "adfs_authority_url": null,
            "admin_password": null,
            "admin_username": "testuser",
            "allocated": true,
            "api_profile": "latest",
            "append_tags": true,
            "auth_source": "auto",
            "availability_set": null,
            "boot_diagnostics": null,
            "capacity_reservation_group": null,
            "cert_validation_mode": null,
            "client_id": null,
            "cloud_environment": "AzureCloud",
            "created_nsg": true,
            "custom_data": null,
            "data_disks": null,
            "disable_instance_discovery": false,
            "ephemeral_os_disk": null,
            "eviction_policy": null,
            "force": false,
            "generalized": false,
            "image": {
                "community_gallery_image_id": "/CommunityGalleries/fedora-5e266ba4-2250-406d-adad-5d73860d958f/Images/Fedora-Cloud-40-x64/Versions/latest"
            },
            "license_type": null,
            "linux_config": null,
            "location": null,
            "log_mode": null,
            "log_path": null,
            "managed_disk_type": "Premium_LRS",
            "max_price": -1.0,
            "name": "community-gallery-image-vm",
            "network_interface_names": [
                "myNIC"
            ],
            "open_ports": [
                "33"
            ],
            "os_disk_caching": null,
            "os_disk_encryption_set": null,
            "os_disk_name": null,
            "os_disk_size_gb": null,
            "os_type": "Linux",
            "password": null,
            "plan": null,
            "priority": null,
            "profile": null,
            "proximity_placement_group": null,
            "public_ip_allocation_method": "Static",
            "remove_on_absent": [
                "all"
            ],
            "resource_group": "my-test",
            "restarted": false,
            "secret": null,
            "security_profile": null,
            "short_hostname": null,
            "ssh_password_enabled": false,
            "ssh_public_keys": [
                {
                    "key_data": "<< REDACTED >>",
                    "path": "/home/testuser/.ssh/authorized_keys"
                }
            ],
            "started": null,
            "state": "present",
            "storage_account_name": null,
            "storage_blob_name": null,
            "storage_container_name": "vhds",
            "subnet_name": null,
            "subscription_id": null,
            "swap_os_disk": null,
            "tags": null,
            "tenant": null,
            "thumbprint": null,
            "virtual_network_name": null,
            "virtual_network_resource_group": null,
            "vm_identity": null,
            "vm_size": "Standard_B1ms",
            "windows_config": null,
            "winrm": null,
            "x509_certificate_path": null,
            "zones": null
        }
    },
    "msg": "Error creating or updating virtual machine community-gallery-image-vm - (InvalidParameter) The value of parameter imageReference.publisher is invalid.\nCode: InvalidParameter\nMessage: The value of parameter imageReference.publisher is invalid.\nTarget: imageReference.publisher"
}

@Fred-sun
Copy link
Collaborator Author

@arvindshmicrosoft You are still using an older version of azure.azcollection (azure-mgmt-compute API version v2021_04_01), but this version does not yet support the 'community_gallery_image_id' parameter. You need to update azure.azcollection (latest: v3.0.0), also required in the installation package (azure-mgmt-compute ==33.0.0, API version v2024-07-01). Thank you!

@arvindshmicrosoft
Copy link

@Fred-sun thank you for pointing that out, and apologies for missing the updated. Your change looks good once I upgraded to azure.azcollection 3.0.0 and associated latest requirements.

@xuzhang3 xuzhang3 merged commit 78ada32 into ansible-collections:dev Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium_priority Medium priority new_feature New feature requirments ready_for_review The PR has been modified and can be reviewed and merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Community Gallery image ID in azure_rm_virtualmachine and azure_rm_virtualmachinescaleset
3 participants