Assign variable to previous node/node list in job workflow

44 views
Skip to first unread message

Loth

unread,
Feb 1, 2023, 5:00:00 PM2/1/23
to rundeck-discuss
Hey All,

I have a task that requires things to be migrated from one node to the previous in a chain. To do this I need to make a job that can reference either one of the following;

1. The entire node list used for a job, in order of execution (taking account the rank attribute). From this I can identify the current node and subtract one for my purpose.
2. Find the previous node in the execution list (NULL if the first node)

Are any of these possible in the community version of rundeck?

Thanks for any replies.

rac...@rundeck.com

unread,
Feb 2, 2023, 9:15:02 AM2/2/23
to rundeck-discuss
Hi,

You can obtain that list with this endpoint.

I made a curl call that prints the node list used for a job (considering the rank attribute order), keep in mind that by design, that node info is only available after an execution.

curl -sS -X GET 'http://localhost:4440/api/41/execution/<execution_id>/output' --header 'Accept: application/json' --header 'X-Rundeck-Auth-Token: <your_api_token>' | jq -r '.entries[].node'

You can save this list in a data variable using the Multiline Regex Data Capture Filter and pass it to other steps. Also, you can play with how the nodes are printed using jq.

Regards.

Loth

unread,
Feb 2, 2023, 10:29:02 AM2/2/23
to rundeck...@googlegroups.com
Hello,

Thanks for the reply.

I do need this data for the current job execution, I know it is not
available at the current execution however is it available on step 2+
of the same job, or only after the job is 100% completed? If this is
the case, is my option #2 viable?

Thanks again.
> --
> You received this message because you are subscribed to the Google Groups "rundeck-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rundeck-discu...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rundeck-discuss/fba602f0-01de-40dd-816c-18d6bc3f1c6dn%40googlegroups.com.

rac...@rundeck.com

unread,
Feb 2, 2023, 2:13:19 PM2/2/23
to rundeck-discuss
The second option sounds viable, a good approach could be to build this in an inline script step or on different steps:

a) Run the first job via API (you can use this endpoint).
b) Wait some seconds.
c) Get the execution id (from "a", this needs some "script-fu", the jq tool could be useful)
d) Use the api+jq call to get the previous job execution nodes and then save it on a data variable.

Regards!

Loth

unread,
Feb 2, 2023, 2:41:04 PM2/2/23
to rundeck...@googlegroups.com
Ok thanks, this sounds doable. So the first job would just be a dummy
run (just an echo or something) to get this data into the RD API? And
the second is where the workflow that actually needs this data
happens?
> To view this discussion on the web visit https://groups.google.com/d/msgid/rundeck-discuss/354cc99d-195f-4144-8893-f328b0fdc4d6n%40googlegroups.com.

Loth

unread,
Feb 2, 2023, 8:03:47 PM2/2/23
to rundeck...@googlegroups.com
Hello,

Alternatively is it possible to assign ${node.name} =
${export.lastHost} as an exported global variable to other nodes? Or
is that impossible to do?

Thanks!

rac...@rundeck.com

unread,
Feb 3, 2023, 8:05:44 AM2/3/23
to rundeck-discuss
Hi, that's challenging.

Directly ${node.name} -> ${export.lasthost} isnt't possible

... But we can play with data variables in this way:

${node.name} -> ${data.mydata} -> ${export.lasthost}

I attached a job definition example. Feel free to modify it if you like :-)

Hope it helps!
HelloWorld.yaml
Reply all
Reply to author
Forward
0 new messages