我想只在第一个节点发生故障时才在备用节点上执行作业。
备用节点表示第一个节点的副本。 这是为了备份第一个节点,以防第一个节点出现故障或维护。
如何在rundeck上配置作业?
任何帮助表示赞赏。
答案 0 :(得分:0)
据我所知,没有直接的方法,但您可以尝试使用API并使用任何首选语言进行编码。
1,在节点1上使用rundeck执行作业并获取执行ID。这里使用节点过滤器来选择第一个节点 2,检查该ID的执行状态 3,如果上述执行成功,你就会变得更好,不需要进一步。如果它失败,请执行第1步与第二个节点一起使用,并确保使用node filter方法选择第二个节点。
使用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:~$
此处,执行ID为1154.要获取执行状态,
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:~$
如果执行失败,您将收到状态失败的响应
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:~$