我的 ansible-playbook 正在運行一些帶有 async 標簽的長時間運行的任務,并且還利用了“creates:”條件,所以它只在服務器上運行一次。當我昨天寫劇本時,我很確定,當“creates:”標簽中的日志集存在時,任務被跳過了。
每次我運行它時,它現在都顯示改變了。
我很困惑,因為我認為我沒有改變任何東西,當條件為真時,我想正確地將我注冊的變數設定為未更改。
ansible-play 的輸出(除錯部分顯示任務已更改:true):
TASK [singleserver : Install Assure1 SingleServer role] *********************************************************************************************************************************
changed: [crassure1]
TASK [singleserver : Debug] *************************************************************************************************************************************************************
ok: [crassure1] => {
"msg": {
"ansible_job_id": "637594935242.28556",
"changed": true,
"failed": false,
"finished": 0,
"results_file": "/root/.ansible_async/637594935242.28556",
"started": 1
}
}
但是如果我檢查目標機器上的實際結果檔案,它正確地解決了條件并且沒有實際執行 shell 腳本,所以任務應該保持不變(顯示訊息,因為日志存在,任務被跳過):
[root@crassure1 assure1]# cat "/root/.ansible_async/637594935242.28556"
{"invocation": {"module_args": {"warn": true, "executable": null, "_uses_shell": true, "strip_empty_ends": true, "_raw_params": "/opt/install/install_command.sh", "removes": null, "argv": null, "creates": "/opt/assure1/logs/SetupWizard.log", "chdir": null, "stdin_add_newline": true, "stdin": null}}, "cmd": "/opt/install/install_command.sh", "changed": false, "rc": 0, "stdout": "skipped, since /opt/assure1/logs/SetupWizard.log exists"}[root@crassure1 assure1]# Connection reset by 172.24.36.123 port 22
我的劇本部分如下所示:
- name: Install Assure1 SingleServer role
shell:
#cmd: "/opt/assure1/bin/SetupWizard -a --Depot /opt/install/:a1-local --First --WebFQDN crassure1.tspdata.local --Roles All"
cmd: "/opt/install/install_command.sh"
async: 7200
poll: 0
register: Assure1InstallWait
args:
creates: /opt/assure1/logs/SetupWizard.log
- name: Debug
debug:
msg: "{{ Assure1InstallWait }}"
- name: Check on Installation status every 15 minutes
async_status:
jid: "{{ Assure1InstallWait.ansible_job_id }}"
register: job_result
until: job_result.finished
retries: 30
delay: 900
when: Assure1InstallWait is changed
是我遺漏了什么,還是某種錯誤?
我受到配置的可信存盤庫中可用的 Ansible 版本的限制,所以我使用的是 ansible 2.9.25
uj5u.com熱心網友回復:
問:“每次運行時,模塊外殼顯示都發生了變化”
A: 在異步模式下,任務不能立即跳過。首先,模塊外殼必須找出檔案/opt/assure1/logs/SetupWizard.log是否存在于遠程主機上。然后,如果檔案存在,模塊將決定跳過命令的執行。但是,您異步運行任務。在這種情況下,Ansible 啟動模塊并回傳,無需等待模塊完成。這就是注冊變數Assure1InstallWait所說的。任務開始了,但還沒有完成。
"msg": {
"ansible_job_id": "637594935242.28556",
"changed": true,
"failed": false,
"finished": 0,
"results_file": "/root/.ansible_async/637594935242.28556",
"started": 1
}
設定這樣一個任務改變的決定是正確的,我認為是因為遠程主機上的執行正在進行。
列印模塊async的注冊結果。您會看到,該命令已被跳過,因為檔案存在(您已在遠程列印異步檔案)。這里更改的屬性設定為false因為現在我們知道命令沒有執行
job_result:
...
attempts: 1
changed: false
failed: false
finished: 1
msg: Did not run command since '/tmp/SetupWizard.log' exists
rc: 0
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/403382.html
標籤:
上一篇:如何在C#中運行回圈異步
