Octopus Deploy – different IIS Bindings for different target servers

Problem: Using Octopus Deploy, you wish to deploy IIS web site to two target servers in an environment but you want those servers to have different IIS Bindings.

For example, your live environment contains 2 web servers called Sandbox1 and Sandbox2 which are load balanced. (Note these are the Octopus target names)

First create two project variables as follows (Note that the names are case sensitive):

variable 1

Name        IsSandbox1   
Value       #{if Octopus.Machine.Name == "Sandbox1"}true#{/if}#{unless  Octopus.Machine.Name == "Sandbox1"}false#{/unless}
Scope       Staging, Live

variable 2

Name        IsSandbox2   
Value       #{if Octopus.Machine.Name == "Sandbox2"}true#{/if}#{unless  Octopus.Machine.Name == "Sandbox2"}false#{/unless}
Scope       Staging, Live

In the Web Site deployment step, you then create bindings with custom expression for the Enabled field like this:

For the Sandbox1 binding….

#{if IsSandbox1}true#{/if}#{unless IsSandbox1}false#{/unless}

For the Sandbox2 binding….

#{if IsSandbox2}true#{/if}#{unless IsSandbox2}false#{/unless}

Azure load balancer – by powershell

Work in progress…

#Login-AzureRmAccount

## remove from loadbalancer

$rgName = ‘Sandbox’
$nicName = ‘nic1’

$nic = Get-AzureRmNetworkInterface -ResourceGroupName $rgName -Name $nicName

$nic.IpConfigurations[0].LoadBalancerBackendAddressPools = $null

Set-AzureRmNetworkInterface -NetworkInterface $nic

#####3—- add to load balancer

$LoadBalancerName = ‘SandboxLoadBalancer’

$nic = Get-AzureRmNetworkInterface -ResourceGroupName $rgName -Name $nicName

$lb = Get-AzureRmLoadBalancer -Name $LoadBalancerName -ResourceGroupName $rgName

$nic.IpConfigurations[0].LoadBalancerBackendAddressPools = $lb.BackendAddressPools

Set-AzureRmNetworkInterface -NetworkInterface $nic