[英]How can I run more complex job dependencies via Rundeck
我目前正在為我正在研究的一些 PoC 測試 Rundeck。 我目前只能通過 docker 在一台機器上運行它,所以我無法訪問多個節點。
我想模擬以下工作依賴項:
JobB 和 JobC 需要 JobA。 但是 JobB 和 JobC必須並行運行。
如果當前本地時間是上午 9:00,則必須運行 JobC。 作業 A 是否已完成/開始並不重要。
所有這些都應該能夠輕松擴展和擴展到數百個 Job。
你們中的一些人可以幫助我嗎? 我嘗試了幾種配置,包括插件作業狀態。 我不知何故無法讓它工作。 我能做的最好的事情就是按順序或並行運行所有作業。
實現這一目標的最佳(也是最簡單)方法是使用規則集策略(僅在 PagerDuty Process Automation On Prem 上可用,以前稱為“Rundeck Enterprise”)使用作業參考步驟調用您的作業。
因此,在社區版本中,“解決方法”是通過Rundeck API從父作業調用作業,這基本上是關於編寫自定義工作流行為的腳本, 例如:
工作A
- defaultTab: nodes
description: ''
executionEnabled: true
id: b156b3ed-fde6-4fdc-af81-1ee919edc4ff
loglevel: INFO
name: JobA
nodeFilterEditable: false
plugins:
ExecutionLifecycle: null
scheduleEnabled: true
sequence:
commands:
- exec: whoami
keepgoing: false
strategy: node-first
uuid: b156b3ed-fde6-4fdc-af81-1ee919edc4ff
工作B
- defaultTab: nodes
description: ''
executionEnabled: true
id: 4c46c795-20c9-47a8-aa2e-e72f183b150f
loglevel: INFO
name: JobB
nodeFilterEditable: false
plugins:
ExecutionLifecycle: null
scheduleEnabled: true
sequence:
commands:
- exec: whoami
keepgoing: false
strategy: node-first
uuid: 4c46c795-20c9-47a8-aa2e-e72f183b150f
JobC(每天上午 9 點運行,無論 JobA 執行如何)。
- defaultTab: nodes
description: ''
executionEnabled: true
id: ce45c4d1-1350-407b-8001-2d90daf49eaa
loglevel: INFO
name: JobC
nodeFilterEditable: false
plugins:
ExecutionLifecycle: null
schedule:
month: '*'
time:
hour: '09'
minute: '00'
seconds: '0'
weekday:
day: '*'
year: '*'
scheduleEnabled: true
sequence:
commands:
- exec: whoami
keepgoing: false
strategy: node-first
uuid: ce45c4d1-1350-407b-8001-2d90daf49eaa
ParentJob(所有行為邏輯都在 bash 腳本中,需要jq工具才能工作)
- defaultTab: nodes
description: ''
executionEnabled: true
id: 6e67020c-7293-4674-8d56-5db811ae5745
loglevel: INFO
name: ParentJob
nodeFilterEditable: false
plugins:
ExecutionLifecycle: null
scheduleEnabled: true
sequence:
commands:
- description: A friendly starting message
exec: echo "starting..."
- description: Execute JobA and Get the Status
fileExtension: .sh
interpreterArgsQuoted: false
plugins:
LogFilter:
- config:
invalidKeyPattern: \s|\$|\{|\}|\\
logData: 'true'
regex: ^(job_a_exec_id)\s*=\s*(.+)$
type: key-value-data
script: "# execute JobA\nexec_id=$(curl -s -X POST \\\n \"http://localhost:4440/api/41/job/b156b3ed-fde6-4fdc-af81-1ee919edc4ff/run\"\
\ \\\n --header \"Accept: application/json\" \\\n --header \"X-Rundeck-Auth-Token:\
\ 45hNfblPiF6C1l9CfJeG37l08oAgs0Gd\" | jq .id)\n \necho \"job_a_exec_id=$exec_id\""
scriptInterpreter: /bin/bash
- description: Time to execute the Job
exec: sleep 2
- description: 'Get the execution Status '
fileExtension: .sh
interpreterArgsQuoted: false
plugins:
LogFilter:
- config:
invalidKeyPattern: \s|\$|\{|\}|\\
logData: 'false'
regex: ^(job_a_exec_status)\s*=\s*(.+)$
type: key-value-data
script: "exec_status=$(curl -s -X GET \\\n 'http://localhost:4440/api/41/execution/@data.job_a_exec_id@'\
\ \\\n --header 'Accept: application/json' \\\n --header 'X-Rundeck-Auth-Token:\
\ 45hNfblPiF6C1l9CfJeG37l08oAgs0Gd' | jq -r .status)\n \necho \"job_a_exec_status=$exec_status\""
scriptInterpreter: /bin/bash
- description: 'Run JobB and JobC pararelly, depending on JobA Execution Status'
fileExtension: .sh
interpreterArgsQuoted: false
script: "# Now execute JobB and JobC depending on the JobA final status (dependency)\n\
\nif [ @data.job_a_exec_status@ = \"succeeded\" ]; then\n echo \"Job A execition\
\ is OK, running JobB and JobC pararelly...\"\n \n # JobB \n curl -X POST\
\ \\\n \"http://localhost:4440/api/41/job/4c46c795-20c9-47a8-aa2e-e72f183b150f/run\"\
\ \\\n --header \"Accept: application/json\" \\\n --header \"X-Rundeck-Auth-Token:\
\ 45hNfblPiF6C1l9CfJeG37l08oAgs0Gd\" &\n \n # JobC\n curl -X POST \\\n\
\ \"http://localhost:4440/api/41/job/ce45c4d1-1350-407b-8001-2d90daf49eaa/run\"\
\ \\\n --header \"Accept: application/json\" \\\n --header \"X-Rundeck-Auth-Token:\
\ 45hNfblPiF6C1l9CfJeG37l08oAgs0Gd\" &\nelse\n echo \"Job A has failed, dependencey\
\ failed\"\nfi"
scriptInterpreter: /bin/bash
- description: A friendly ending message
exec: echo "done."
keepgoing: false
strategy: node-first
uuid: 6e67020c-7293-4674-8d56-5db811ae5745
父作業的 JobB/JobC 啟動腳本:
# Now execute JobB and JobC depending on the JobA final status (dependency)
if [ @data.job_a_exec_status@ = "succeeded" ]; then
echo "Job A execition is OK, running JobB and JobC pararelly..."
# JobB
curl -X POST \
"http://localhost:4440/api/41/job/4c46c795-20c9-47a8-aa2e-e72f183b150f/run" \
--header "Accept: application/json" \
--header "X-Rundeck-Auth-Token: 45hNfblPiF6C1l9CfJeG37l08oAgs0Gd" &
# JobC
curl -X POST \
"http://localhost:4440/api/41/job/ce45c4d1-1350-407b-8001-2d90daf49eaa/run" \
--header "Accept: application/json" \
--header "X-Rundeck-Auth-Token: 45hNfblPiF6C1l9CfJeG37l08oAgs0Gd" &
else
echo "Job A has failed, dependencey failed"
fi
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.