2014-10-01 15 views
19

Kayıt ifadesinin standart çıktısına dayalı olarak ne zaman ifadesini kullanırım? Eğer standart çıkış var ise standart bir çıkış yoksa bazı komutların çalışmasını istiyorum.Sonuç stdoutuna dayanan Ansible koşullu mu?

- hosts: myhosts 
    tasks: 
    - name: echo hello 
    command: echo hello 
    register: result 
    - command: somecommand {{ result.stdout }} 
    when: result|success 
    - command: someothercommand 
    when: result|failed 

cevap

42

Boş bir dizgiye eşit olup olmadığını görmek için denetlemeyi deneyin.

- hosts: myhosts 
    tasks: 
    - name: echo hello 
    command: echo hello 
    register: result 
    - command: somecommand {{ result.stdout }} 
    when: result.stdout != "" 
    - command: someothercommand 
    when: result.stdout == "" 
+0

İşte bu, bir while deyiminde result.stdout == "" kullanarak okumaya yeni başlamıştım ve sonra yanıt vermiştiniz. Teşekkür ederim! – ibash