This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

⚠️ We've moved!

Hi there!

To reduce project dependency on 3rd party paid services the StackStorm TSC has decided to move the Q/A from this forum to Github Discussions. This will make user experience better integrated with the native Github flow, as well as the questions closer to the community where they can provide answers.

Use 🔗 Github Discussions to ask your questions.

Add new key/value to dictionary in an array

I’m looking to be able to add a new key and value to a dictionary/object that is located in an array of dictionaries/objects, but I’m struggling at how to do so.

Scenario:

I’m looking to build a workflow that will deploy a VM and then make some adjustments inside the VM after deployment. Ideally, I would like to pass an array of dictionaries/objects to be able to deploy multiple VMs at once using “with items” in the tasks.

Below is an example of what I’m looking to pass to the workflow:

[
  {
   "Domain" : "example1.com",
   "Param1" : "burger1",
   "Param2" : "hotdog1",
   "Param3" : "soda1"
  },
  {
   "Domain" : "example2.com",
   "Param1" : "burger2",
   "Param2" : "hotdog2",
   "Param3" : "soda2"
  },
  {
   "Domain" : "example3.com",
   "Param1" : "burger3",
   "Param2" : "hotdog3",
   "Param3" : "soda3"
  }
 ]

The issue is that the IP address to access the VM isn’t known until the VM is deployed. What I would like to do is add the IP to the dictionary used to deploy the VM, such as going from:

{
 "Domain" : "example1.com",
 "Param1" : "burger1",
 "Param2" : "hotdog1",
 "Param3" : "soda1"
}

to:

{
 "Domain" : "example1.com",
 "Param1" : "burger1",
 "Param2" : "hotdog1",
 "Param3" : "soda1",
 "IPAddress" : "127.0.0.1"
}

Has anyone added done this before and can point me in the direction I should head to achieve it?

You’ll need some logic to edit your dictionaries inside of the list, but here is how to add a key/value to a dictionary-

Task1:
  action: core.noop
  next:
    - when: <% [True statement here]%>
      publish:
        - dictionary: <% ctx(dictionary).set("IPAddress" => "127.0.0.1")) %>
      do: Task2