Need help to parse output

Hello, I have a task that loops to get user details in one same server. The exceededCPUUsers contains the list of the users.
For example:
exceededCPUUsers: [user1, user2]

This is the task in a workflow:

Task3:
    action: core.remote
    with: <% ctx().exceededCPUUsers %>
    input:
      username: root
      hosts: "{{ ctx().hostname }}"
      cmd: "checkpkg user={{ item() }}"
    next:
      - when: <% succeeded() %>
        publish:
          - getPackage: <% task(Task3).result %>

It saves the output to getPackage like this : https://pastebin.com/Vm7R34ag

I’m struggling with the list inside list part (items list and hostname list) .I need suggestion on how to make the output like this: https://pastebin.com/3ZdcRF4i

As you can see the hostname list is merged, and the item() from exceededCPUUsers become keys. I think it’s like changing from nested list into dict inside list.

I really appreciate the help.

What errors are you getting? What YAQL query have you tried so far?

FYI, the example you shared via pastebin (https://pastebin.com/Vm7R34ag) is not valid JSON.

I tried this query:
<% task(Task3).result.items.select($.result) %>

So far, it looks like this : https://pastebin.com/5EcdFxJv Now I don’t know how to merge the item list so the hostname only shows once, and use exceededCPUUsers as key.

The pastebin is correct, except in the final output because I want to illustrate the final output.

The data restructuring you’re attempting to do is too complex for YAQL or Jinja, you’ll need to process it with a general purpose language.

1 Like

Yeah I do think the structure is too complex. I’ll try another way. Thank you for your help.