How to execute jobs on alternate node only if first node failed

648 views Asked by At

I want to execute jobs at alternate node only if first node failed.

The alternate node means a copy of first node. This is for backup of first node just in case of the first node in trouble or maintenace.

How do I configure the job on rundeck?

Any help appreciate.

1

There are 1 answers

2
Leo Prince On

There is no direct method as far as I know, however you can try a work around using API and coding with any of your preferred language.

1, Execute the job using rundeck on node 1 and get the execution ID. Here use node filter for selecting the first node 2, Check the status of the execution of that ID 3, if the above execution succeeded, you're good and nothing further required. In case if it's failed, do the step 1 function with the second node and make sure you use node filter method to select the second node.

Sample job execution using rundeck API

leo@leo-OptiPlex-3020:~$ curl -X POST -H "X-Rundeck-Auth-Token:************************" localhost:4440/api/1/job/949d9733-e55e-4bd2-9bc2-6a083807a363/run
<result success='true' apiversion='14'>
  <executions count='1'>
    <execution id='1154' href='http://localhost:4440/project/Testing/execution/show/1154' permalink='' status='running' project='Testing'>
      <user>admin</user>
      <date-started unixtime='1483966018421'>2017-01-09T12:46:58Z</date-started>
      <job id='949d9733-e55e-4bd2-9bc2-6a083807a363' averageDuration='2738' href='http://localhost:4440/api/14/job/949d9733-e55e-4bd2-9bc2-6a083807a363' permalink='http://localhost:4440/project/Testing/job/show/949d9733-e55e-4bd2-9bc2-6a083807a363'>
        <name>A</name>
        <group></group>
        <project>Testing</project>
        <description>A</description>
      </job>
      <description>#!/bin/bash
A=testA
echo $A [... 2 steps]</description>
      <argstring />
    </execution>
  </executions>
</result>leo@leo-OptiPlex-3020:~$ 

Here, execution ID is 1154. To get the status of the execution,

leo@leo-OptiPlex-3020:~$ curl -H "X-Rundeck-Auth-Token:*************************" localhost:4440/api/1/execution/1154
<result success='true' apiversion='14'>
  <executions count='1'>
    <execution id='1154' href='http://localhost:4440/project/Testing/execution/show/1154' permalink='' status='succeeded' project='Testing'>
      <user>admin</user>
      <date-started unixtime='1483966018000'>2017-01-09T12:46:58Z</date-started>
      <date-ended unixtime='1483966020000'>2017-01-09T12:47:00Z</date-ended>
      <job id='949d9733-e55e-4bd2-9bc2-6a083807a363' averageDuration='2766' href='http://localhost:4440/api/14/job/949d9733-e55e-4bd2-9bc2-6a083807a363' permalink='http://localhost:4440/project/Testing/job/show/949d9733-e55e-4bd2-9bc2-6a083807a363'>
        <name>A</name>
        <group></group>
        <project>Testing</project>
        <description>A</description>
      </job>
      <description>#!/bin/bash
A=testA
echo $A [... 2 steps]</description>
      <argstring />
      <successfulNodes>
        <node name='localhost' />
      </successfulNodes>
    </execution>
  </executions>
</result>leo@leo-OptiPlex-3020:~$ 

If the execution failed, you will get a response like this with failed status

leo@leo-OptiPlex-3020:~$ curl -H "X-Rundeck-Auth-Token:*******************" localhost:4440/api/1/execution/1155
<result success='true' apiversion='14'>
  <executions count='1'>
    <execution id='1155' href='http://localhost:4440/project/Testing/execution/show/1155' permalink='' status='failed' project='Testing'>
      <user>admin</user>
      <date-started unixtime='1483966084000'>2017-01-09T12:48:04Z</date-started>
      <date-ended unixtime='1483966086000'>2017-01-09T12:48:06Z</date-ended>
      <job id='949d9733-e55e-4bd2-9bc2-6a083807a363' averageDuration='2766' href='http://localhost:4440/api/14/job/949d9733-e55e-4bd2-9bc2-6a083807a363' permalink='http://localhost:4440/project/Testing/job/show/949d9733-e55e-4bd2-9bc2-6a083807a363'>
        <name>A</name>
        <group></group>
        <project>Testing</project>
        <description>A</description>
      </job>
      <description>#!/bin/bash
ls /sdbksncsklj</description>
      <argstring />
      <failedNodes>
        <node name='localhost' />
      </failedNodes>
    </execution>
  </executions>
</result>leo@leo-OptiPlex-3020:~$