I am trying to provision 4 different instances on AWS and then run a runbook on each one of them. The issue is that i save as Octopus variable the hostname, the public and the private ip of each instance and would need to pass these parameters dynamically in the runbook that contains a powershell script.
Is there any way to implement this?
I’d recommend taking a look at prompted variables. These variables can pass through to your script and allow you to get the specific values for each target so your runbook completes successfully. In addition to the prompted variables, you can take a look at the Run Octopus Deploy Runbook step template, as well as the run-runbook CLI command, both of which can allow you to orchestrate the runbook invocation with prompted variables specified.
Let me know if you run into any other questions or issues, happy to help!
Hi @cory.reid ,
I saw you mentioned Prompt Variables, had kind of a similar scenario but I was trying to use multiple values in one variable scoped, however within the script it was giving a null value, until, I remove the Scope, is this normal behavior?
Thanks in Advance!
Hey there @andrew4 ,
That definitely sounds like an issue with scoping! It looks like you’re scoping to both a role (
Access) and a target machine. Best bet is to confirm the following:
- The target machine
Accessrole (verifiable from Infrastructure -> Deployment Targets)
- Your deployment process execution location is set to
Run on each deployment target. If you’re running from a worker, the role will never apply, and your variables won’t resolve properly.
As an aside, your code sample shows assigning
server.hostname.project to both values - just something to look out for
Thanks for your reply. Having a variable
server.hostname.project with two values, scoped to different machines, should pick up the value accordingly though right? so the first value would be assigned to
mt5-loadtesting-trade01 that has the
Access role whilst when running the same on
MVP with the
Access role should pick up the second value, or I have the wrong understanding?
You were spot-on with the issue, I had that particular step running on Octopus Server, I would need to use Output Variables to pass them from previous steps I guess?
Thanks for your help!
You are correct, the variables do assign that way with scoping. The only thing that caused you issues was that you were using target specific scoping, but not running on the targets.
Running on the targets themselves, you should see the correct variable behavior.
Hi @cory.reid ,
Thank you for the reply above.
If i can add to this discussion to present you our issue and any further help is greatly appreciated:
we define a variable set within the project with 3 different variables: public ip, private ip and hostname.
These variables have multiple values so for each new instance we create, we add the newly variable value set under the same variables but for a different target.
The problem is that we define these variables as output variables on the very first step of a runbook that need to be run on each different target. This runbook is triggered automatically via terraform inline powershell and as a first step of the runbook there is the definition of the output variables in order to be used for the rest of the steps during the deployment of the different targets.
The problem is that for the second step of the runbook, some times the variables are passed correctly but some other times they are passed null.
We cannot narrow down the issue and we have questions on the following:
- For the definition of the output variables on the first step of the runbook, will the step run on the different deployment targets or on the Octopus server, since the variables are stored on the Octopus server.
- Do we need to define on the second step where we call the variables, the name of the machine in which the output variables are populated? For example if on the first step we run it on the Octopus server, do we need to define the machine name of the octopus node on the second step where we call them?
It seems that we are missing something and any help would be really appreciated.
Hey there @1n3l4st1c - I’m still looking into this, hoping to have something that can help unblock you tomorrow!
Thanks for keeping in touch! I’ll jump in here for Cory as he’s currently offline as part of our US-based team.
To create machine-specific values to this variable, you would want the step that creates this output variable to run on each applicable machine. Octopus will create multiple values to this same output variable, for each machine, where each value is scoped to the machine.
The second step being run on the same machines as step one, when calling the output variable it’ll automatically choose the right value per machine based on scope. If you want to grab the value created on a different machine than what the 2nd step is being run on, you can also call this specific output variable value by indexing on the machine name. This is in addition to #1 above - Octopus creates non scoped values, indexed by machine, allowing you to call them cross-machine, with
I hope this helps! Please let me know if you have any further questions, or if I’ve misunderstood what you’re after in any way.
Thank you very much Kenneth will give it a test.
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.