2017-02-23 30 views
0

我有一个任务运行并重试shell命令,直到某个字符串不在日志文件的最后一行。它每秒重试500次。Ansible |使重试任务在多个服务器上异步运行

当条件满足时,它关闭服务器。当使用serial: 1一次运行一台服务器时,这非常有效。

但是我想一次在多台服务器上运行它。问题在于它会在所有服务器关闭之前等待所有服务器满足条件。

我希望它异步运行并关闭每台服务器,因为该服务器符合条件。

我试过async: truepoll: 0,但在任务中使用retry: true时似乎不起作用。

这是一段代码片段,让您知道我在做什么。

- name: "Checking for inactivity on the server before shutdown" 
    shell: "tail -1 serverlogs.log | egrep 'STRING1|STRING2' ||:" 
    args: 
    chdir: "/path/to/log/" 
    register: check_inactivity 
    until: '"STRING1" not in check_inactivity.stdout and "STRING2" not in check_inactivity.stdout' 
    retries: 500 
    delay: 1 



- name: Debug message 
    debug: 
    msg: "Shutting down the server | {{ inventory_hostname }}" 
    when: 'check_inactivity | changed' 

这是想什么我实现

- name: "Checking for inactivity on the server before shutdown" 
    shell: "tail -1 serverlogs.log | egrep 'STRING1|STRING2' ||:" 
    args: 
    chdir: "/path/to/log/" 
    register: check_inactivity 
    until: '"STRING1" not in check_inactivity.stdout and "STRING2" not in check_inactivity.stdout' 
    retries: 500 
    delay: 1 
    async: 45 
    poll: 0 


- name: Debug message 
    debug: 
    msg: "Shutting down the server | {{ inventory_hostname }}" 
    when: 'check_inactivity | changed' 

这可能吗?

回答

0

设置strategyfree

- hosts: all 
    strategy: free 
    tasks: 
    ... 

这将指示Ansible尽可能快地运行在每个主机上的任务,而无需等待在一组的其他主机。

+0

谢谢。这按需要工作! –