How to determine a linux vm is an Azure VM using ansible?

Gary BORTHWICK 0 Reputation points
2023-11-06T07:43:21.34+00:00

We have common ansible code that runs against a variety of VMs and also physical servers. We use the "when" condition to determine if the code is to run against a particular VM based on the "vendor" Azure, VMware, AWS, HP Proliant. . .

We are new to working with Azure VMs and would like to know if there is a best practice for determining if a VM is an Azure VM .

We have come across. .

Azure has a chassis asset tag value of 7783-7084-3265-9085-8269-3286-77 and so can do in ansible
azure_chassis_asset_tag: '7783-7084-3265-9085-8269-3286-77'

chassis_asset_tag : "{{ lookup('file', '/sys/devices/virtual/dmi/id/chassis_asset_tag',errors='ignore') }}"

and compare values for a VM and react accordingly.

Is this a valid technique and is there anything better available?

Thanks

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
8,016 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Andreas Baumgarten 111.4K Reputation points MVP
    2023-11-06T07:55:15.74+00:00

    Hi @Gary BORTHWICK ,

    as far as I know the chassis asset tag value 7783-7084-3265-9085-8269-3286-77 could be Azure or Azure Stack.

    There is no guarantee the asset tag value for Azure/Azure Stack will be same in the future.

    But for now this is a possible solution to classify VMs in Azure.

    Another option to identify Azure VMs could be the IP address of an VM if there is no overlapping IP address ranges in Azure and on-premises.


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards

    Andreas Baumgarten

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.