Setting value of runbook process step dynamically

Im creating a runbook that creates azure infrastructure - step 1 create rg , step 2 create vm using arm . how do i set the name of the rg dynamically created in step 1 in step 2 , where i need to select a rg along with azure account . the deploy a arm template step explicitly needs a rg selected … Please advise. Thank you !

Hi @vinayak.tillu,

Thanks for reaching out.

Depending on how you’re creating the resource group in step 1, you could store the value in an output variable (documentation: https://octopus.com/docs/projects/variables/output-variables), and then in step 2 you could set the value of your resource group to that output variable.

Do you think that will work in your setup?

Please let me know what you think.

Thanks,
Jeremy

Hi Jeremy

Thank you for reaching out. I will look into out-variables

I could perhaps show you whats going on through the screen shots or a shared session

The step where I need to select resource group based on the azure account selected before , requires resource group to exist .

Hi @vinayak.tillu,

If you select the Azure account, then click the bind button to the right, it should allow you to type in a variable in the resource group section, like in this screenshot:

Please let me know if it works on your end and if the test run works with the output variable.

Please let me know if you have any questions.

Thanks,
Jeremy

Thanks Jeremy. That worked for me.
I had another quick question.
While creating dynamic infra I also need to create deployment target and environment in octopus for it.
Could you point me to octopus powershell that helps with it.
Vinayak

Hi @vinayak.tillu,

You’re very welcome! I’m glad to hear it worked.

You can do that via some API calls.

For registering a tentacle, you can check this repository: https://github.com/OctopusDeploy/OctopusDeploy-Api/tree/master/REST/PowerShell/Targets
It has register listening, polling, and SSH target scripts.

I don’t see any example scripts for creating an environment, but what I like to do when I want to do something with an API call is, I will open the Developer Tab on my browser with F12, and go to the Network tab, then finally I will manually do the thing I want to do with an API call within the portal and watch the API calls and look at the headers. So for your case, I would go to the environments page, click add environment, and then hit F12 and watch the API call as you create the environment.

I did it myself and it looks like its a POST call to http://192.168.139.160/api/Spaces-1/environments , with the body of something like:

{
   "Name":"Teeeeest",
   "Description":"",
   "UseGuidedFailure":false,
   "AllowDynamicInfrastructure":false,
   "SortOrder":-1,
   "ExtensionSettings":[
  
   ]
}

Please let me know if that answers your question or if you need more help.

Thanks,
Jeremy

Thank you Jeremy. Environments work. So i create an environment and when i can add the environment detail to ARM templates octopus extension which installs a polling agent , creates a deployment target and also adds it to the environment. Now the only challenge is i have an existing lifecycle and a default phase to which i need to add this environment. I was looking into the api for that but if you could provide some insights, that will be great. Thank you !

Hi @vinayak.tillu,

Sorry about the delay. I was on vacation since the 20th.

It looks like that’s a POST call to http://SERVERURL/api/Spaces-1/lifecycles/Lifecycles-#####

with a payload of :

{
   "Id":"Lifecycles-22",
   "SpaceId":"Spaces-1",
   "Phases":[
      {
         "Id":"beb374ba-1598-4e00-8dc5-27a4bf78a6a3",
         "Name":"Test",
         "AutomaticDeploymentTargets":[
            
         ],
         "OptionalDeploymentTargets":[
            "Environments-21",
            "Environments-1"
         ],
         "MinimumEnvironmentsBeforePromotion":0,
         "IsOptionalPhase":false,
         "ReleaseRetentionPolicy":null,
         "TentacleRetentionPolicy":null
      }
   ],
   "Name":"Test",
   "ReleaseRetentionPolicy":{
      "Unit":"Items",
      "QuantityToKeep":3,
      "ShouldKeepForever":false
   },
   "TentacleRetentionPolicy":{
      "Unit":"Days",
      "QuantityToKeep":0,
      "ShouldKeepForever":true
   },
   "Description":"",
   "Links":{
      "Self":"/api/Spaces-1/lifecycles/Lifecycles-22",
      "Preview":"/api/Spaces-1/lifecycles/Lifecycles-22/preview",
      "Projects":"/api/Spaces-1/lifecycles/Lifecycles-22/projects"
   }
} 

In my case, I was just adding an environment to the phase Test.

You would likely need to bring down the JSON body of the desired lifecycle with a GET call, do some iteration to find the correct phase, then add it in the appropriate spot, then use a POST call to that API endpoint. If you want to follow the API call in the browser, it won’t actually do anything until you click the save button.

Does that help? Please let me know if you get it going or need more assistance.

Thanks,
Jeremy

Hi Jeremy

Thank you for it .

I have more of an architectural question .

We are creating a runbook that creates a resource group in azure .

It needs to create n number of virtual machines in that resource group.

The resource group in azure maps to an environment in octopus and each VM maps to a deployment target .

Each virtual machine also maps to a tenant in octopus.

But when I execute a process step for the runbook , I can only run it for a particular tag set. Which means I need to add the newly created vm into that tag set.

Visualizing this whole plumbing is a bit of a challenge right now. Can we have a screen share session so that I can get some inputs on it.

Thank you

Vinayak

Hi @vinayak.tillu,

You’re very welcome.

I spoke with someone in advice and they’d like to see screenshots of your runbook and deployment process. If you need to privately message for security reasons please feel free to do so.

Thanks,
Jeremy

Thank you ! How can I privately message ?

Hi,

You would just click my name then click message.

Please let me know if it doesn’t work for you.

Thanks,
Jeremy

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.