首页 > 解决方案 > Rundeck - 作业导入不适用于 yaml

问题描述

我正在使用这个 Rundeck 作业导入的 API,从我当地的邮递员那里,我可以使用正文中给定的 yaml 进行作业导入。

但是当我尝试对本地的 curl 执行相同操作时,它失败了:

[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>

即使在使用fileformat=yaml等所有选项付出了很多之后,它也不起作用。

请让我知道我做错了什么。

标签: rundeck

解决方案


它适用于以下调用(在 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"

以及以下作业定义示例(job.yaml 文件):

- 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

推荐阅读