azureterraformansible-inventoryazure-availability-set

Find Fault Domain for given VM/instance in Azure


I have a Scale Set I provisioned in Azure through Terraform.
(A scale set is an implicit availability set with 5 fault domains and 5 update domains.[ [1]])

I need to find out which Fault Domain each instance is in, so that I can configure my application cluster based on this, for improved redundancy.

So far, I have found only a single post remotely addressing thisenter link description here.

More context:

Many many thanks, –Jeff


Solution

  • I have solved this by using the 169.254.169.254 'virtual IP' that allows a VM in the could to read its own metadata.

    Specifically, I am running:

    curl -H Metadata:true --silent "http://169.254.169.254/metadata/instance/compute/platformFaultDomain?api-version=2017-03-01&format=text"
    

    in an Ansible task, and then using Ansible's local facts to make this available as an Ansible variable on the host.