Reputation: 4490
I am using the API for this Rundeck job import, from my local postman I could able to do the job import with the given yaml in the body.
but when I try to do the same with curl from my local it is failing:
[root@vms ]# curl -k --location --request POST 'rundeck-host:4443/api/14/project/project-name/jobs/import' --header 'Content-Type: application/yaml' --header 'X-Rundeck-Auth-Token: my-token' --data @job.yaml
<result error='true' apiversion='33'>
<error code='api.error.jobs.import.invalid'>
<message>Jobs Document was invalid for format xml: mapping values are not allowed here
in 'reader', line 1, column 33:
- defaultTab: nodes description: '' executionEnabled: true gr ...
^
</message>
</error>
</result>
Even after paying a lot with all the option like fileformate=yaml and other, it does not work.
Please let me know what I am doing wrong.
Upvotes: 0
Views: 1224
Reputation: 4325
It works with the following call (tested on Rundeck 3.3.10):
#!/bin/sh
# protocol
protocol="http"
# basic rundeck info
rdeck_host="localhost"
rdeck_port="4440"
rdeck_api="38"
rdeck_token="2aoZkhOR0ZSwMIZo4Sg6hrY57NfiN4nB"
# specific api call info
rdeck_project="ProjectEXAMPLE"
rdeck_yaml_file="job.yaml"
# api call
curl -kSsv --header "X-Rundeck-Auth-Token:$rdeck_token" \
-F xmlBatch=@"$rdeck_yaml_file" \
"$protocol://$rdeck_host:$rdeck_port/api/$rdeck_api/project/$rdeck_project/jobs/import?fileformat=yaml"
And the following job def example (job.yaml file):
- defaultTab: nodes
description: ''
executionEnabled: true
id: 24d326d4-5fa9-4f42-98d6-b27b338fa7ff
loglevel: INFO
name: HelloWorld
nodeFilterEditable: false
plugins:
ExecutionLifecycle: null
scheduleEnabled: true
sequence:
commands:
- exec: echo "hi"
keepgoing: false
strategy: node-first
uuid: 24d326d4-5fa9-4f42-98d6-b27b338fa7ff
Upvotes: 1
Reputation: 4490
I was able to manage this curl working, I did not pass the yaml as file but yaml as data for curl and it worked.
Ideal as Rundeck has mentioned it does support the yaml as file format so it should entertain yaml file base rest call.
Command and output: (again the output also I can not format to json even after passing extra params)
curl -k --location --request POST 'rundeck-node:4443/api/14/project/project-name/jobs/import' --header 'Content-Type: application/yaml' --header 'X-Rundeck-Auth-Token: your-token' --data "$(cat job-to-import.yaml)"
<result success='true' apiversion='33'>
<succeeded count='1'>
<job index='1' href='rundeck-node:4443/api/33/job/410b1862-504a-4a52-beb0-8ba4ecc5f174'>
<id>410b1862-504a-4a52-beb0-8ba4ecc5f174</id>
<name>your-job-name</name>
<group>job-group-name-if-any</group>
<project>project-name</project>
<permalink>rundeck-node:4443/project/project-name/job/show/410b1862-504a-4a52-beb0-8ba4ecc5f174</permalink>
</job>
</succeeded>
<failed count='0' />
<skipped count='0' />
</result>
Please comment or write another answer if you find the proper way of doing this operation.
Upvotes: 0