azurevirtual-machineazure-hdinsightazure-rm-template

How to list IP of Azure VM or HDI cluster after deployment using ARM template in the output


I have created ARM template to deploy Azure VM and HDI cluster. I want to get and list the Public IP of Azure VM and Private IP of HDI cluster headnode after deployment is finished.

Is there a way to get it using ARM template?


Solution

  • Is there a way to get it using ARM template?

    Based on my knowledge, you could not get VM IP with template.You could use azure cli to get your VM IP instead of template. If your cli on Linux, you could use the following command after you create your VM.

    azure vm show -g shui123 -n shui|grep "Public IP address"| awk -F: '{print $3}'
    

    I want to get and list the Public IP of Azure VM and Private IP of HDI cluster headnode after deployment is finished.

    Public IP of Azure VM do you mean? Just VM or VM in HDI cluster?

    If it is just a VM, you could use the command above, if it is VM in HDI cluster, Azure HDInsight cluster will not allow any public IP to be assigned to it. if you need a IP to be allocated to HDInsight cluster, you would have to create HDInsight in a VNET. the following article does talk about this.

    You could get HDI cluster IP with ​Ambari ​RE​ST ​AP​I.

    for HOSTNAME in $(curl -u admin:$PASSWORD -sS -G "https://shuitest.azurehdinsight.net/api/v1/clusters/shuitest/hosts" | jq -r '.items[].Hosts.host_name')
    do
        IP=$(curl -u admin:$PASSWORD -sS -G "https://$CLUSTERNAME.azurehdinsight.net/api/v1/clusters/$CLUSTERNAME/hosts/$HOSTNAME" | jq -r '.Hosts.ip')
      echo "$HOSTNAME <--> $IP"
    done
    

    More information about Ambari ​RE​ST ​AP​I please refer to this link.

    Update:

    If you only want to list active node IP, you could use the following commands.

    PASSWORD=
    CLUSTERNAME=
    
    curl -u admin:$PASSWORD -sS -G "https://$CLUSTERNAME.azurehdinsight.net/api/v1/clusters/$CLUSTERNAME/services/HDFS/components/NAMENODE" |grep LiveNode>test.txt
    
    cat test.txt |awk -F'\' '{print $2}'|sed 's/\"//g'|tail -1|awk -F: '{print $1}'