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

`azure_rm_virtualmachinescaleset` Module not Updating VMSS tags #1653

Closed Jacob-Steele closed 2 months ago

Jacob-Steele commented 2 months ago
SUMMARY

When using module azure_rm_virtualmachinescaleset and specifying tags:, tags on the VMSS are not updated.

ISSUE TYPE
COMPONENT NAME

azure_rm_virtualmachinescaleset

ANSIBLE VERSION
% ansible --version
ansible [core 2.17.1]
  config file = /Users/jsteele/development/ansible-forge/ansible.cfg
  configured module search path = ['/Users/jsteele/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/jsteele/development/ansible-forge/.venv/ansible/lib/python3.11/site-packages/ansible
  ansible collection location = /Users/jsteele/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/jsteele/development/ansible-forge/.venv/ansible/bin/ansible
  python version = 3.11.7 (main, Mar 28 2024, 13:34:34) [Clang 15.0.0 (clang-1500.1.0.2.5)] (/Users/jsteele/development/ansible-forge/.venv/ansible/bin/python3)
  jinja version = 3.1.4
  libyaml = True
COLLECTION VERSION
ansible-galaxy collection list azure.azcollection      

# /Users/jsteele/.ansible/collections/ansible_collections
Collection         Version
------------------ -------
azure.azcollection 2.6.0 
CONFIGURATION
ansible-config dump --only-changed
CALLBACKS_ENABLED(/Users/jsteele/development/ansible-forge/ansible.cfg) = ['timer', 'profile_tasks']
CONFIG_FILE() = /Users/jsteele/development/ansible-forge/ansible.cfg
OS / ENVIRONMENT
ProductName:            macOS
ProductVersion:         13.6.3
BuildVersion:              22G436
STEPS TO REPRODUCE

We have a role that's running the azure_rm_virtualmachinescaleset module to update a VMSS that already exists on Azure. I have one tag associated with this VMSS called test:blarg mainly to figure out if this is working.

- name: Update Scale Set With New Tags
  azure_rm_virtualmachinescaleset:
    resource_group: "{{ resource_group }}"
    name: "{{ scale_set_name }}"
    capacity: "1"
    orchestration_mode: "{{ scale_set_orchestration_mode | default('Uniform') }}"
    tags:
      app: "user"
      env: "env"
      tier: "dev"
      app_type: "api"
      version: "version"
EXPECTED RESULTS

Tags on the VMSS are updated to be

            "tags": {
                "test": "blarg",
                "app": "user",
                "env": "env",
                "app_type": "api",
                "tier": "dev",
                "version": "version"
            },
ACTUAL RESULTS

Tags are not updated on the VMSS

As shown in the below output, it picks up the original tag under ansible_facts of

            "tags": {
                "test": "blarg"
            },

it also picks up the new tags under invocation of

            "tags": {
                "app": "user",
                "env": "env",
                "app_type": "api",
                "tier": "dev",
                "version": "version"
            },

But the VMSS isn't actually updated. I can keep running this role with the exact same parameters, and the VMSS will always be changed, but the tags are never updated.

TASK [azure.vmss_deploy : Update Scale Set With New Image] *********************************************************************************************************
task path: /Users/jsteele/.ansible/collections/ansible_collections/azure/roles/vmss_deploy/tasks/main.yml:59
Thursday 25 July 2024  14:18:15 -0400 (0:00:01.875)       0:00:07.032 ********* 
redirecting (type: modules) ansible.builtin.azure_rm_virtualmachinescaleset to azure.azcollection.azure_rm_virtualmachinescaleset
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: jsteele
<127.0.0.1> EXEC /bin/sh -c 'echo ~jsteele && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/jsteele/.ansible/tmp `"&& mkdir "` echo /Users/jsteele/.ansible/tmp/ansible-tmp-1721931495.141694-70485-93787762539183 `" && echo ansible-tmp-1721931495.141694-70485-93787762539183="` echo /Users/jsteele/.ansible/tmp/ansible-tmp-1721931495.141694-70485-93787762539183 `" ) && sleep 0'
redirecting (type: modules) ansible.builtin.azure_rm_virtualmachinescaleset to azure.azcollection.azure_rm_virtualmachinescaleset
Using module file /Users/jsteele/.ansible/collections/ansible_collections/azure/azcollection/plugins/modules/azure_rm_virtualmachinescaleset.py
<127.0.0.1> PUT /Users/jsteele/.ansible/tmp/ansible-local-703451jo5nscw/tmp_t7v709w TO /Users/jsteele/.ansible/tmp/ansible-tmp-1721931495.141694-70485-93787762539183/AnsiballZ_azure_rm_virtualmachinescaleset.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /Users/jsteele/.ansible/tmp/ansible-tmp-1721931495.141694-70485-93787762539183/ /Users/jsteele/.ansible/tmp/ansible-tmp-1721931495.141694-70485-93787762539183/AnsiballZ_azure_rm_virtualmachinescaleset.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/Users/jsteele/development/ansible-forge/.venv/ansible/bin/python3 /Users/jsteele/.ansible/tmp/ansible-tmp-1721931495.141694-70485-93787762539183/AnsiballZ_azure_rm_virtualmachinescaleset.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /Users/jsteele/.ansible/tmp/ansible-tmp-1721931495.141694-70485-93787762539183/ > /dev/null 2>&1 && sleep 0'
[WARNING]: Module did not set no_log for ssh_password_enabled
changed: [localhost] => {
    "ansible_facts": {
        "azure_vmss": {
            "do_not_run_extensions_on_overprovisioned_v_ms": false,
            "id": "/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Compute/virtualMachineScaleSets/example-vmss",
            "identity": {
                "type": "UserAssigned",
                "user_assigned_identities": {
                    "/subscriptions/REDACTED/resourcegroups/REDACTED/providers/Microsoft.ManagedIdentity/userAssignedIdentities/REDACTED": {
                        "client_id": "REDACTED",
                        "principal_id": "REDACTED"
                    },
                    "/subscriptions/REDACTED/resourcegroups/REDACTED/providers/Microsoft.ManagedIdentity/userAssignedIdentities/REDACTED": {
                        "client_id": "REDACTED",
                        "principal_id": "REDACTED"
                    }
                }
            },
            "location": "eastus",
            "name": "example-vmss",
            "orchestration_mode": "Uniform",
            "overprovision": true,
            "platform_fault_domain_count": 1,
            "provisioning_state": "Succeeded",
            "single_placement_group": false,
            "sku": {
                "capacity": 1,
                "name": "Standard_DS2_v2",
                "tier": "Standard"
            },
            "tags": {
                "test": "blarg"
            },
            "type": "Microsoft.Compute/virtualMachineScaleSets",
            "unique_id": "REDACTED",
            "upgrade_policy": {
                "mode": "Automatic"
            },
            "virtual_machine_profile": {
                "extension_profile": {
                    "extensions": []
                },
                "network_profile": {
                    "network_interface_configurations": [
                        {
                            "dns_settings": {
                                "dns_servers": []
                            },
                            "enable_accelerated_networking": false,
                            "enable_ip_forwarding": false,
                            "ip_configurations": [
                                {
                                    "load_balancer_backend_address_pools": [
                                        {
                                            "id": "/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Network/loadBalancers/REDACTED/backendAddressPools/BackEndAddressPool"
                                        }
                                    ],
                                    "name": "default",
                                    "primary": true,
                                    "private_ip_address_version": "IPv4",
                                    "subnet": {
                                        "id": "/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Network/virtualNetworks/REDACTED/subnets/REDACTED"
                                    }
                                }
                            ],
                            "name": "example-vmss",
                            "primary": true
                        }
                    ]
                },
                "os_profile": {
                    "admin_username": "user",
                    "computer_name_prefix": "example-vmss",
                    "linux_configuration": {
                        "disable_password_authentication": true,
                        "provision_vm_agent": true,
                        "ssh": {
                            "public_keys": [
                                {
                                    "key_data": "REDACTED",
                                    "path": "/home/user/.ssh/authorized_keys"
                                }
                            ]
                        }
                    },
                    "secrets": []
                },
                "storage_profile": {
                    "image_reference": {
                        "id": "/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Compute/galleries/REDACTED/images/user-Ubuntu-2204/versions/20240718.20.06"
                    },
                    "os_disk": {
                        "caching": "ReadOnly",
                        "create_option": "FromImage",
                        "disk_size_gb": 30,
                        "managed_disk": {
                            "storage_account_type": "Standard_LRS"
                        },
                        "os_type": "Linux"
                    }
                }
            }
        }
    },
    "changed": true,
    "invocation": {
        "module_args": {
            "ad_user": null,
            "adfs_authority_url": null,
            "admin_password": null,
            "admin_username": null,
            "api_profile": "latest",
            "append_tags": true,
            "application_gateway": null,
            "auth_source": "auto",
            "capacity": 1,
            "cert_validation_mode": null,
            "client_id": null,
            "cloud_environment": "AzureCloud",
            "custom_data": null,
            "data_disks": null,
            "disable_instance_discovery": false,
            "enable_accelerated_networking": null,
            "ephemeral_os_disk": null,
            "eviction_policy": null,
            "identity": null,
            "image": null,
            "load_balancer": null,
            "location": null,
            "log_mode": null,
            "log_path": null,
            "managed_disk_type": null,
            "max_price": -1.0,
            "name": "example-vmss",
            "orchestration_mode": "Uniform",
            "os_disk_caching": "ReadOnly",
            "os_disk_size_gb": null,
            "os_type": "Linux",
            "overprovision": null,
            "password": null,
            "plan": null,
            "platform_fault_domain_count": 1,
            "priority": null,
            "profile": null,
            "public_ip_per_vm": false,
            "remove_on_absent": [
                "all"
            ],
            "resource_group": "REDACTED",
            "scale_in_policy": null,
            "secret": null,
            "security_group": null,
            "security_profile": null,
            "short_hostname": null,
            "single_placement_group": false,
            "ssh_password_enabled": true,
            "ssh_public_keys": null,
            "state": "present",
            "subnet_name": null,
            "subscription_id": null,
            "tags": {
                "app": "user",
                "env": "env",
                "app_type": "api",
                "tier": "dev",
                "version": "version"
            },
            "tenant": null,
            "terminate_event_timeout_minutes": null,
            "thumbprint": null,
            "tier": null,
            "upgrade_policy": null,
            "virtual_network_name": null,
            "virtual_network_resource_group": null,
            "vm_size": null,
            "x509_certificate_path": null,
            "zones": null
        }
    }
}
Jacob-Steele commented 2 months ago

As a note to others with the same problem, we can workaround this by using azure_rm_resource, but it's not ideal. e.g.

- name: Get VMSS State
  azure_rm_resource:
    resource_group: "{{ resource_group }}"
    provider: compute
    resource_type: virtualMachineScaleSets
    resource_name: "{{ scale_set_name }}"
    api_version: "2023-09-01"
    method: "GET"
  register: vmss_api_response

- name: Update VMSS Tags
  azure_rm_resource:
    resource_group: "{{ resource_group }}"
    provider: compute
    resource_type: virtualMachineScaleSets
    resource_name: "{{ scale_set_name }}"
    api_version: "2023-09-01"
    method: "PATCH"
    body: "{{ vmss_api_response.response | combine({'tags': scale_set_tags}) }}"
Fred-sun commented 2 months ago

@Jacob-Steele Fixed in #1654

Jacob-Steele commented 2 months ago

@Jacob-Steele Fixed in #1654

Thank you so much @Fred-sun for the fast turn around on this 🎉