在云端 Rundeck 上运行预定作业

问题描述

我已安排 rundeck 作业在云中的各种服务器实例上运行,并且这些实例由作业中的实例 ID 引用。问题在于,当重新配置实例时,Rundeck 作业会失败,因为该实例现在具有新 ID。有人有解决这个问题的方法吗?

解决方法

一个好的方法是按以下顺序使用数据传递功能:1) 创建一个提供您的实例 2) 获取新 id(可能通过 api 与您的“云提供商”)和 3)将该 id 用于任何事情。

我留下一个基本的例子/假作业定义来测试:

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='current_node' value='9272c5fbfdd2ed332592ab565318c55d' />
      </options>
    </context>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <executionEnabled>true</executionEnabled>
    <id>e7e973aa-987d-40c2-8883-be00191113cd</id>
    <loglevel>INFO</loglevel>
    <name>CloudJob</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <description>Reprovisioning the instance. Later catch the new id. This step have an log filter attach to get the id and save it on data value (using a regex).</description>
        <fileExtension>.sh</fileExtension>
        <plugins>
          <LogFilter type='key-value-data'>
            <config>
              <invalidKeyPattern>\s|\$|\{|\}|\\</invalidKeyPattern>
              <logData>true</logData>
              <regex>^(id)\s*:\s*(.+)$</regex>
            </config>
          </LogFilter>
        </plugins>
        <script><![CDATA[# reprovisioning simulation
echo "current instance id:@option.current_node@"
echo "provisioning the instance..."
sleep 3
echo "instance reprovisioned..."

# in this part you must caught the new id (maybe via cloud provider api?)
echo "id:9d42d17404ec17b41861879305fd454b" # new id
echo "have a nice day :-)"]]></script>
        <scriptargs />
        <scriptinterpreter>/bin/bash</scriptinterpreter>
      </command>
      <command>
        <description>now you can do anything with new id (stored at ${data.id} option</description>
        <exec>echo "the new id is ${data.id}"</exec>
      </command>
    </sequence>
    <uuid>e7e973aa-987d-40c2-8883-be00191113cd</uuid>
  </job>
</joblist>

Here 您可以看到有关键值日志过滤器使用的更多信息。还有 here 一个关于数据传递功能的好例子。