So I’m trying to find a way to get the deployment target IPs and pass them to our NLB.
The current setup is, we deploy to three targets. 1 Backend, 2 Frontend Servers.
Now I want to get the IP’s from the 2 FE servers but they are known only by their internal hostnames (fe1.infra.myorg.com) in the deployment target (tentacle url is fe1…etc…:port).
How can I get all IP Adresses of our 2FE Servers and store them in a variable? This has to be done via script because we have about 250 FE Servers running. So setting variables for this doesnt make sense
I found something like this:
$ipV4 = Test-Connection -ComputerName (hostname) -Count 1 | Select IPV4Address
Set-OctopusVariable -name "IPV4Address" -value $ipV4.IPV4Address
I guess this script would run “on each deployment target”. But this would overwrite itself as soon as it is run on the other FE instance… The targets have a “frontend-server” role, so running only in fe is not an issue… Just the saving of the variable.
OR, if you have another Idea… Let me know if there is a better way to do it.
Greets & Thanks.
Thanks for getting in touch!
Is the scenario going to be a single deployment that has one step to retrieve the IPs and then another step that makes use of them?
If so, output variables, like in the script you found, would be the best option. When running a script like that on multiple deployment targets, it should save the returned value per target which you would then retrieve with
More details on this here.
Hey Paul, thanks for the reply… But in this case, I would need to know the Target and name it… right?
but with 250 targets, Its impossible to do that…
We have something like:
So I think it would make more sense to have a process variable where I can just add two values? Like an array or something like that…?
// Edit… Just realized that all variables are just strings… so this would not work as well… also, because I need that variable in a “install helm chart” task…
You mentioned that this was only for two targets, so, I assumed that you would have the two target names available?
Or could the two servers be any two out of the entire 250?
You could potentially have the end script iterate through all of the targets within the specified Role and when it finds a non-null value record the target name (if needed) and IP value.
Ok, so lets say we have 70 tenants, each with their own two FE targets.
So to get the IP Adresses, i would:
Start the process (lets just say 1 here, but it will run 70 times)
- run a script on each target with role fe to get the ipadress of this target and save it to a variable
- run a script on octopus server iterating through ALL (70*2) targets with the role fe and look if any of those have a value, write this value in two generic variables (HOSTIP1, HOSTIP2)
- use HOSTIP1 and HOSTIP2 in the helm install task as value-overrides
That sounds so wrong and complicated for just simply getting an IP of something we already have a connection to…
What is the execution location of the
helm install task set to?
If it is running on the Server/Worker, then, unfortunately, it is completely unaware of the deployment targets used earlier in the process and the values will need to be passed to it through output variables.
If the script is running on the deployment target or on behalf of the deployment target, then it would be able to retrieve the target name with the
[Octopus.Machine.Name] system variable. This would mean that the entire script would run once for each target though, which depending on the content of the script may be undesirable.
I spent some time working on this with our solutions team to see if we can come up with a good solution and the main issue we encounter is that the output variable requires the machine name but all of our system variables return the machine ID.
So, the best option we could come up with was to run a script that would scan through the available Output variables and return all of the values for the specific variable name, in this case,
$IpAddressList = @()
foreach ($param in $OctopusParameters.Keys)
if ($param -match "Octopus\.Action\[.+\]\.Output\[.+\]\.IPAddress")
$IpAddressList += $OctopusParameters[$param]
Actually, this looks good… thanks a lot!
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.