Accessing variables for a machine from another machine

Hello everyone.

Is it possible to access the variables applied to a specific machine from another machine? For example, let’s say we have 1 environment with three machines - M (role master), W1 and W2 (role web). I want to be able to access certain variables that have been applied to W1 and W2 from M. A solution that works now is to set variables that apply to machine M, but this way I have to copy variables that already exist for W1 and W2.

I thought I could do the following:

  • From W1 and W2 I create a PowerShell script to set a custom output variable
  • On M I use Octopus.Environment.MachinesInRole[web] to get all machines in this role. And then Octopus.Action[MyAction].Output[Machine].MyVariable. However, MachinesInRole returns a list of IDs, not names.

Alternatively, is it possible when I am using Set-OctopusVariable, every machine (W1 and W2) to populate an array with some values and then M to read the values from that array?

Looking forward to hearing your comment :slight_smile:

Hi Boyan,

Thanks for getting in touch! If W1 and W2 set an output variable, on M you can do:

$w1Value = $OctopusParameters["Octopus.Action[StepA].Output[W1].MyValue"]
$w2Value = $OctopusParameters["Octopus.Action[StepA].Output[W2].MyValue"]

There’s a few more examples here if you haven’t seen them yet:

It’s a bit more difficult to dynamically get an array from all set values - the best would be to iterate over the $OctopusParameters dictionary, and try to pattern match (e.g., keys that start with Octopus.Action[StepA].Output.[ and end with ].MyValue).

Let me know if this makes sense or if there’s something I’ve missed. Hope this helps!

Paul

Hi Paul,

Thanks for the answer. I think iterating over the variables could do the trick. The think is that I don’t want to hard-code the names W1 and W2. Basically I want to get all the machines (in a specific role) that the current deployment has been applied to. But seems there is no way to get their names from variables.