0
我正在嘗試使用正確的操作手冊並行啓動幾個作業。 我必須發佈到http才能開始工作;一旦工作排隊,完成工作可能需要1-3分鐘。我需要在後臺並行啓動幾個作業,然後輪詢日誌以獲取成功消息或失敗的消息,並且還需要超時。我有ssh訪問SERVERNAME,所以正則表達式搜索部分非常有效;但是我沒有找到一種方法來使它在日誌中發現「Started Failed」時失敗。試過的狀態=缺席,但似乎適用於其他wait_for組件。如何使用異步運行Ansible並行任務並檢查日誌成功/失敗
這一切都可以Ansible?我想出下面的yaml。
---
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: Launch an http POST
async: 10
poll: 0
uri:
url: "https://SERVERNAME/MYLINK1"
method: POST
headers:
Content-Type: "application/x-www-form-urlencoded"
status_code: 200
validate_certs: no
timeout: 10
return_content: yes
register: response1
- name: Launch an http POST
async: 10
poll: 0
uri:
url: "https://SERVERNAME/MYLINK2"
method: POST
headers:
Content-Type: "application/x-www-form-urlencoded"
status_code: 200
validate_certs: no
timeout: 10
return_content: yes
register: response2
- name: Wait Job to be ready
async: 120
delegate_to: SERVERNAME
wait_for:
path: /usr/local/logs/mylog1.log
search_regex: "Started Success"
register: wait_for_success1
- name: Wait Job to be failed
async: 120
delegate_to: SERVERNAME
wait_for:
path: /usr/local/logs/mylog1.log
search_regex: "Started Failed"
register: wait_for_failed1
- name: Wait Job to be ready
async: 120
delegate_to: SERVERNAME
wait_for:
path: /usr/local/logs/mylog2.log
search_regex: "Started Success"
register: wait_for_success=2
- name: Wait Job to be failed
async: 120
delegate_to: SERVERNAME
wait_for:
path: /usr/local/logs/mylog2.log
search_regex: "Started Failed"
register: wait_for_failed2