0
votes

I have an OUTPUTS section in my template:

  "outputs": {
    "MasterFirstIPConfig": {
      "type": "string",
      "value": "[reference(variables('masterVM'),'2016-09-01').ipConfigurations[0].properties.privateIPAddress]"
    }
  }

And it works as expected - I see VM's Private IP.

Next - I'd like to use this IP as an argument to CustomScript extension, which looks like:

              "settings": {
                "fileUris": [
                  "https://utils.blob.core.windows.net/scripts/swarm_master_provision.sh"
                ],
                "commandToExecute": "[concat('bash swarm_master_provision.sh ', reference(variables('masterVM'),'2016-09-01').ipConfigurations[0].properties.privateIPAddress)]"

              },

The problem here is that reference() lead to dependency error:

error: InvalidTemplate : Deployment template validation failed: 'Circular dependency detected on resource: '/subscriptions/0a4f2b9c-***-40b17ef8c3ab/resourceGroups/jm-web-test-var-1/providers/Microsoft.Compute/virtualMachineScaleSets/jm-web-test-var-1-master-vmss'. Please see https://aka.ms/arm-template/#resources for usage details.'.

So question is - how can I pass private IP to the script?

2
@4c74356b41 Hi again :-) Thanks for comment - added link to the template.setevoy
@4c74356b41 No problem) Just let me please know when I can remove the template from Github (even without sensitive information - it's still a customer's code).setevoy
so do you want to pass the same parameter to both extensions or how you want to do that?4c74356b41
@4c74356b41 Yes, exactly. The plan is - run joint for workers and additional managers via script. But to do it - need to obtain any manager's IP, wich was deployed to master's VMSS and pass it as an argument to the CustomScript.setevoy

2 Answers

0
votes

So as you are making the IP static but letting it be assigned by the VM deployment, you are unable to reference that IP within the same resource. Makes sense.

One way of doing this would be to seperate the NIC from the VM. Instead of having it as a child resource of the VM, make it its own resource, then have the VM depend on the NIC. Then you can assign a static IP to the NIC, then reference the NIC in the network profile section of the VM, and the IP of the nic in the custom script extension.

Edit: Ah this might only work with VMs not scale sets...

Edit2: Also, the reference function is only for use in the output section of the template. After a bit more research, it looks like you can assign the IP address to the load balancer. That might work for you!

0
votes

Ok, so I'm up to something here, I propose you work around that with a nested template approach.

I won't paste the whole template, but just remove the extension configuration from master VMSS, and move it to a separate template, and in your template create a new step like this:

{
    "apiVersion": "2015-01-01",
    "name": "VMSSextension",
    "type": "Microsoft.Resources/deployments",
    "dependsOn": [
        "[concat('Microsoft.Compute/virtualMachineScaleSets/', variables('masterVMSSname'))]"
    ],
    "properties": {
        "mode": "Incremental",
        "templateLink": {
            "uri": "http://pastebin.com/raw/GsNTiAMc", ## << You can take a look at the nested template
            "contentVersion": "1.0.0.0"
        },
        "parameters": {
            "value": {
                "value": "[variables('masterVMSSname')]"
            },
            "value2": {
                "value": "[reference(variables('masterVM'),'2016-09-01').ipConfigurations[0].properties.privateIPAddress]"
            }
        }
    }
}

The only real downside - you have to upgrade the scale set members that are initially provisioned to the latest version. all the new ones would be latest (so with custom script extension). And for your "slave" VMSS, you shouldn't need nested template approach, just make it "dependOn" the "master" VMSS.

edit: Sorry it took me so long, kinda short on time nowadays.