2016-12-21 17 views
2

我正試圖編寫一個在linux主機中運行的進程數不等於2時顯示失敗的劇本。以下劇本的作品,但是有沒有更好的方法呢?像是有任何具體的Ansible模塊來檢查進程的Linux主機?ansible playbook:check linux process count

--- 
    - hosts: web 
    become: yes 
    become_method: su 
    become_user: webuser 
    tasks: 
    - name: process check 
     shell: ps -ef|grep -i etas|grep -v grep|wc -l 
     register: command_result 
     failed_when: "'2' not in command_result.stdout" 

回答

3

什麼是您的Ansible版本?沒有Ansible模塊來計算Linux中的進程數量。你可以使它可讀:

tasks: 
    - name: process check 
    shell: pgrep etas | wc -l 
    register: command_result 
    failed_when: command_result.stdout|int != 2 
+0

謝謝。它工作完美。順便說一句我使用Ansible版本:2.2 – clicks010