How to pass the options with space

126 views
Skip to first unread message

Srimathi S

unread,
Nov 2, 2022, 6:28:37 AM11/2/22
to rundeck-discuss
I want to use the Rundeck API to pass the options in an argstring like this:

{ "argString":" -opt1 hello,script returned exit code1,all"}

But it only uses the data until it locates the empty spaces in Opt 1.(hello,script)

This post method would result a opt1 values as hello,script returned exit code1,all

Can anyone, help me out to solve this !.

rac...@rundeck.com

unread,
Nov 2, 2022, 9:41:49 AM11/2/22
to rundeck-discuss

Hi,

That’s a common curl issue, just escape all variable expansions, it works with the following curl call (check the --data section):

# protocol
protocol="http"
format="json"

# basic rundeck info
rdeck_host="localhost"
rdeck_port="4440"
rdeck_api="41"
rdeck_token="oB8mmGavKld1VmP8ef9kbR2tXBOyhZfO"

# specific api call info
rdeck_job="fcf8cf5d-697c-42a1-affb-9cda02183fdd"
option_value="hello world, bye world, one, two"

# api call
curl --location --request POST "$protocol://$rdeck_host:$rdeck_port/api/$rdeck_api/job/$rdeck_job/run" \
  --header "Accept: application/$format" \
  --header "X-Rundeck-Auth-Token: $rdeck_token" \
  --header "Content-Type: application/$format" \
  --data "{ \"argString\":\"-opt1 '$option_value' \" }"

Result:

{
  "id": 23,
  "href": "http://localhost:4440/api/41/execution/23",
  "permalink": "http://localhost:4440/project/ProjectEXAMPLE/execution/show/23",
  "status": "running",
  "project": "ProjectEXAMPLE",
  "executionType": "user",
  "user": "admin",
  "date-started": {
    "unixtime": 1667395963318,
    "date": "2022-11-02T13:32:43Z"
  },
  "job": {
    "id": "fcf8cf5d-697c-42a1-affb-9cda02183fdd",
    "averageDuration": 369,
    "name": "TokenWorkflow",
    "group": "",
    "project": "ProjectEXAMPLE",
    "description": "",
    "options": {
      "opt1": "hello world, bye world, one, two"
    },
    "href": "http://localhost:4440/api/41/job/fcf8cf5d-697c-42a1-affb-9cda02183fdd",
    "permalink": "http://localhost:4440/project/ProjectEXAMPLE/job/show/fcf8cf5d-697c-42a1-affb-9cda02183fdd"
  },
  "description": "echo ${option.opt1}",
  "argstring": "-opt1 \"hello world, bye world, one, two\"",
  "serverUUID": "a6e565e0-9fd1-4d51-8596-b0f0186eb46d"
}

Check the Rundeck execution here.

Hope it helps!

​

Srimathi S

unread,
Nov 6, 2022, 5:55:13 AM11/6/22
to rundeck...@googlegroups.com
Thank you for your response

--
You received this message because you are subscribed to a topic in the Google Groups "rundeck-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rundeck-discuss/a-rE1lh6B94/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rundeck-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rundeck-discuss/a2ffe563-cd8b-4c1e-b55e-0ed5afb65a2dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages