简体   繁体   English

启动时自动创建 Rundeck 作业(Docker 容器中的 Rundeck)

[英]Auto-create Rundeck jobs on startup (Rundeck in Docker container)

I'm trying to setup Rundeck inside a Docker container.我正在尝试在 Docker 容器内设置 Rundeck。 I want to use Rundeck to provision and manage my Docker fleet.我想使用 Rundeck 来配置和管理我的 Docker 车队。 I found an image which ships an ansible-plugin as well.我发现了一个带有 ansible-plugin 的图像。 So far running simple playbooks and auto-discovering my Pi nodes work.到目前为止,运行简单的剧本和自动发现我的 Pi 节点都可以工作。

Docker script: Docker 脚本:

echo "[INFO] prepare rundeck-home directory"
mkdir ../../target/work/home
mkdir ../../target/work/home/rundeck
mkdir ../../target/work/home/rundeck/data

echo -e "[INFO] copy host inventory to rundeck-home"
cp resources/inventory/hosts.ini ../../target/work/home/rundeck/data/inventory.ini

echo -e "[INFO] pull image"
docker pull batix/rundeck-ansible

echo -e "[INFO] start rundeck container"
docker run -d \
    --name rundeck-raspi \
    -p 4440:4440 \
    -v "/home/sebastian/work/workspace/workspace-github/raspi/target/work/home/rundeck/data:/home/rundeck/data" \
    batix/rundeck-ansible

Now I want to feed the container with playbooks which should become jobs to run in Rundeck.现在我想为容器提供剧本,这些剧本应该成为在 Rundeck 中运行的作业。 Can anyone give me a hint on how I can create Rundeck jobs (which should invoke an ansible playbook) from the outside?谁能给我一个提示,告诉我如何从外部创建 Rundeck 作业(应该调用 ansible 剧本)? Via api?通过 api?

One way I can think of is creating the jobs manually once and exporting them as XML or YAML.我能想到的一种方法是手动创建一次作业并将它们导出为 XML 或 YAML。 When the container and Rundeck is up and running I could import the jobs automatically.当容器和 Rundeck 启动并运行时,我可以自动导入作业。 Is there a certain folder in rundeck-home or somewhere where I can put those files for automatic import? rundeck-home 中是否有某个文件夹或可以放置这些文件以进行自动导入的某个文件夹? Or is there an API call or something?还是有 API 电话或其他什么?

Could Jenkins be more suited for this task than Rundeck? Jenkins 是否比 Rundeck 更适合这项任务?


EDIT: just changed to a Dockerfile编辑:刚刚更改为 Dockerfile

FROM batix/rundeck-ansible:latest

COPY resources/inventory/hosts.ini /home/rundeck/data/inventory.ini
COPY resources/realms.properties /home/rundeck/etc/realms.properties
COPY resources/tokens.properties /home/rundeck/etc/tokens.properties


# import jobs
ENV RD_URL="http://localhost:4440"
ENV RD_TOKEN="yJhbGciOiJIUzI1NiIs"
ENV rd_api="36"
ENV rd_project="Test-Project"
ENV rd_job_path="/home/rundeck/data/jobs"
ENV rd_job_file="Ping_Nodes.yaml"

# copy job definitions and script
COPY resources/jobs-definitions/Ping_Nodes.yaml /home/rundeck/data/jobs/Ping_Nodes.yaml
RUN curl -kSsv --header "X-Rundeck-Auth-Token:$RD_TOKEN" \
    -F yamlBatch=@"$rd_job_path/$rd_job_file" "$RD_URL/api/$rd_api/project/$rd_project/jobs/import?fileformat=yaml&dupeOption=update"

Do you know how I can delay the curl at the end until after the rundeck service is up and running?你知道我怎么能延迟 curl 最后直到 rundeck 服务启动并运行之后?

That's right you can design an script with an API call using cURL (pointing to your Docker instance) after deploying your instance (a script that deploys your instance and later import the jobs), I leave a basic example (in this example you need the job definition in XML format).没错,您可以在部署您的实例后使用cURL (指向您的 Docker 实例)设计一个带有API调用的脚本(一个脚本,用于部署您的基本实例和稍后的导入作业), XML 格式的作业定义)。

For XML job definition format:对于 XML 作业定义格式:

#!/bin/sh

# protocol
protocol="http"

# basic rundeck info
rdeck_host="localhost"
rdeck_port="4440"
rdeck_api="36"
rdeck_token="qNcao2e75iMf1PmxYfUJaGEzuVOIW3Xz"

# specific api call info
rdeck_project="ProjectEXAMPLE"
rdeck_xml_file="HelloWorld.xml"

# api call
curl -kSsv --header "X-Rundeck-Auth-Token:$rdeck_token" \
  -F xmlBatch=@"$rdeck_xml_file" "$protocol://$rdeck_host:$rdeck_port/api/$rdeck_api/project/$rdeck_project/jobs/import?fileformat=xml&dupeOption=update"

For YAML job definition format:对于 YAML 作业定义格式:

#!/bin/sh

# protocol
protocol="http"

# basic rundeck info
rdeck_host="localhost"
rdeck_port="4440"
rdeck_api="36"
rdeck_token="qNcao2e75iMf1PmxYfUJaGEzuVOIW3Xz"

# specific api call info
rdeck_project="ProjectEXAMPLE"
rdeck_yml_file="HelloWorldYML.yaml"

# api call
curl -kSsv --header "X-Rundeck-Auth-Token:$rdeck_token" \
  -F xmlBatch=@"$rdeck_yml_file" "$protocol://$rdeck_host:$rdeck_port/api/$rdeck_api/project/$rdeck_project/jobs/import?fileformat=yaml&dupeOption=update"

Here the API call. 这里是 API 调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM