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.

How to pass json data between tasks

I am worried about how to pass json format output to the next task.

Get EC2 instance creation result as follows.

  "Reservations": [
    {
      "Instances": [
        {
          "Monitoring": {
            "State": "disabled"
          },
          "PublicDnsName": "ec2-XXX-XXX-XXX-XXX.ap-northeast-1.compute.amazonaws.com",
          "State": {
:

The result is standard output by python program as follows.

print(responce)

Then PUBLISH the first task in the workflow and try to use it in task2.

      task1:
         :
        publish:
          json_result: "<% task(task1).result.stdout %>"
        on-success:
          - task2
      task2:
        action: core.local
        input:
           cmd: "echo <% $.result.Reservations[0].Instances[0].PublicDnsName  %> >> /data/ec2.log"

However, executing this workflow results in the following error:

      "state_info": "Failed to run task [error=Can not evaluate YAQL expression [expression=task(task1).result.stdout.Reservations[0].Instances[0].PublicDnsName, error=Unknown function \"#property#Reservations\", data={}], wf=hmpack.deploy_machine.main, task=task2]:
Traceback (most recent call last):
  File \"/opt/stackstorm/mistral/lib/python2.7/site-packages/mistral/engine/task_handler.py\", line 63, in run_task
    task.run()
  File \"/opt/stackstorm/mistral/lib/python2.7/site-packages/osprofiler/profiler.py\", line 160, in wrapper
    result = f(*args, **kwargs)
  File \"/opt/stackstorm/mistral/lib/python2.7/site-packages/mistral/engine/tasks.py\", line 374, in run
    self._run_new()
  File \"/opt/stackstorm/mistral/lib/python2.7/site-packages/osprofiler/profiler.py\", line 160, in wrapper

I’m worried for a while, but I don’t know the cause. Could you tell me the cause?

You should really consider using Orquesta, since Mistral is deprecated and will be removed entirely in a future release.

You have an issue in your YAQL. What do you think $.result is in task2? Start debugging there.

Hi, blag.

Thank you for answering.
I haven’t migrated from mistral yet, but I don’t think there will be much difference in how tasks work together.

Also, the source code was pasted incorrectly.
Correctly,
Not .result ... but .json_result …

How can I debug from here?

I would add a core.echo task that echos out the stringified object that you’re trying to dig through.

      task1:
         :
        publish:
          json_result: "<% task(task1).result.stdout %>"
        on-success:
          - debug
  debug:
    action: core.echo
    input:
      message: <% str($.json_result) %>

That will echo the json_result variable, which should be viewable in the execution results in the web UI or in the CLI.

From there you should be able to see the structure of the data in json_result, which should help you correct your YAQL in task2.

When you migrate from Mistral to Orquesta, you might find this third-party tool helpful:

Hi,blag

Thank you for answering.

The JSON format was received when EC2 was created.
The received JSON format data was output to the standard and the output contents were checked with the jq command, but there seems to be no particular syntax error.

In the first place, is it better to call what is output to the standard output like this?

This time, I switched to Orquesta, but that didn’t work.

If the syntax of JSON is correct, what is the cause?

version: 1.0
name: "hmpack.deploy_machine"
description: "test workflow"

input:
   - AMI_ID
   - Instance_Type
   - Key_Name
   - Tag_Name

tasks:
   create_instance:
      action: hmpack.aws_ec2_create
      input:
        AMI_ID: <% ctx(AMI_ID) %>
        Instance_Type: <% ctx(Instance_Type) %>
        Key_Name: <% ctx(Key_Name) %>
        Tag_Name: <% ctx(Tag_Name) %>
      next:
        - when: <% succeeded() %>
          publish:
            - jsonresult: <% result().stdout %>
          do: echoval

   echoval:
      action: core.local cmd=<% ctx('jsonresult').Reservations[0].Instances[0].PublicDnsName %>