我有节点abcd1,abcd2,abcd3,abcd4
输入= abcd1,abcd3,abcd4,abcd2
如果等级顺序升序-执行如下-abcd1,abcd2,abcd3,abcd4顺序 如果等级顺序降序-执行遵循-abcd4,abcd3,abcd2,abcd1顺序 。 我希望我的执行遵循与输入相同的顺序,即abcd1,abcd3,abcd4,abcd2。如何实现?
答案 0 :(得分:0)
您可以在作业定义上使用“排名属性”选项,为此,只需在节点源上定义(或使用)某些属性,Rundeck便可以使用它,例如,使用此resources.xml
(选中{ {1}}自定义属性):
myorder
现在set使用<?xml version="1.0" encoding="UTF-8"?>
<project>
<node name="node00" description="Node 00" tags="" myorder="02" hostname="192.168.33.20" osArch="amd64" osFamily="unix" osName="Linux" osVersion="3.10.0-1062.4.1.el7.x86_64" username="vagrant" ssh-key-storage-path="keys/rundeck"/>
<node name="node01" description="Node 01" tags="" myorder="03" hostname="192.168.33.21" osArch="amd64" osFamily="unix" osName="Linux" osVersion="3.10.0-1062.4.1.el7.x86_64" username="vagrant" ssh-key-storage-path="keys/rundeck"/>
<node name="node02" description="Node 02" tags="" myorder="01" hostname="192.168.33.22" osArch="amd64" osFamily="unix" osName="Linux" osVersion="3.10.0-1062.4.1.el7.x86_64" username="vagrant" ssh-key-storage-path="keys/rundeck"/>
</project>
属性设置“等级属性”文本框,保存作业并再次运行。您可以根据该属性see订购。
更多信息here。
在此答案的第一条评论之后,存在一种使用bash脚本修改resource.xml文件,稍后更新节点定义并随后使用Job Reference Step将子作业启动到新的rankAttribute顺序的方法。
首先,更改Rundeck模型源的脚本(需要xmlstarlet):
myorder
现在,父作业(调用上面的脚本,刷新Rundeck模型源并最终启动“目标”作业):
#!/bin/bash
path=$RD_OPTION_PATH
myorder=$RD_OPTION_NODE_ORDER
counter=1
Field_Separator=$IFS
# set comma as internal field separator for the string list
IFS=,
for value in $myorder;
do
echo $counter
xmlstarlet ed --inplace -u "/project/node[$counter][@myorder]/@myorder" -v $value $path
counter=$((counter+1))
done
IFS=$Field_Separator
最后是“儿童工作”,即“目标工作”。
<joblist>
<job>
<context>
<options preserveOrder='true'>
<option name='node_order' value='3,2,1' />
<option name='path' required='true' value='/home/m68k/Rundeck/resources/farm.xml' />
</options>
</context>
<defaultTab>nodes</defaultTab>
<description></description>
<executionEnabled>true</executionEnabled>
<id>860e7189-f399-47c4-ab86-5b47017188dd</id>
<loglevel>INFO</loglevel>
<name>Parent</name>
<nodeFilterEditable>true</nodeFilterEditable>
<plugins />
<scheduleEnabled>true</scheduleEnabled>
<sequence keepgoing='false' strategy='sequential'>
<command>
<description>Just a message</description>
<exec>echo "Starting..."</exec>
</command>
<command>
<description>Call the script</description>
<fileExtension>.sh</fileExtension>
<scriptargs />
<scriptfile>/home/m68k/Downloads/TEST.sh</scriptfile>
<scriptinterpreter>/bin/bash</scriptinterpreter>
</command>
<command>
<description>Refresh Rundeck Model Source</description>
<step-plugin type='source-refresh-plugin'>
<configuration>
<entry key='sleep' value='5' />
</configuration>
</step-plugin>
</command>
<command>
<description>And launch the "target" job against the new node order</description>
<jobref name='Child' nodeStep='true'>
<uuid>0e02890e-c9dd-4a65-ace1-bfe90b9b7a8e</uuid>
</jobref>
</command>
</sequence>
<uuid>860e7189-f399-47c4-ab86-5b47017188dd</uuid>
</job>
</joblist>
因此,如果设置<joblist>
<job>
<defaultTab>nodes</defaultTab>
<description></description>
<dispatch>
<excludePrecedence>true</excludePrecedence>
<keepgoing>false</keepgoing>
<rankAttribute>myorder</rankAttribute>
<rankOrder>ascending</rankOrder>
<successOnEmptyNodeFilter>false</successOnEmptyNodeFilter>
<threadcount>1</threadcount>
</dispatch>
<executionEnabled>true</executionEnabled>
<id>0e02890e-c9dd-4a65-ace1-bfe90b9b7a8e</id>
<loglevel>INFO</loglevel>
<name>Child</name>
<nodeFilterEditable>false</nodeFilterEditable>
<nodefilters>
<filter>node.*</filter>
</nodefilters>
<nodesSelectedByDefault>true</nodesSelectedByDefault>
<plugins />
<scheduleEnabled>true</scheduleEnabled>
<sequence keepgoing='false' strategy='node-first'>
<command>
<exec>echo "Hello ${node.name}"</exec>
</command>
</sequence>
<uuid>0e02890e-c9dd-4a65-ace1-bfe90b9b7a8e</uuid>
</job>
</joblist>
顺序,则可以在3,1,2
文件的myorder
属性上看到结果,并且子作业将按照该顺序执行。
resources.xml