Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
453 views
in Technique[技术] by (71.8m points)

instance - Running scheduled jobs on Rundeck in the cloud

I have scheduled rundeck jobs to run on various server instances in the cloud and the instances are referenced by instance ID in the job. The problem is that when a instance is reprovisioned the Rundeck job fails because the instance now has a new ID. Anybody have a solution to the issue?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

A good approach is to use the data passing feature in this order: 1) create a provide your instance 2) get the new id (maybe via api with your "cloud provider") and 3) use that id for anything.

I leave a basic example/fake job definition to test:

<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 you can see more information about key-value log filter use. And here a good example about data passing feature.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...