2016-12-24 68 views
3

是否可以爲可選模塊的單個選項設置條件。如何設置單個可選模塊選項的條件

Using set_fact we can set condition aand use that variable in the ansible module. Alternatively is there any other option to set the condition using if loop in jinja or something like that. 

如:

- name: Simple PUT operation 
    s3: 
    bucket: mybucket 
    object: /my/desired/key.txt 
    src: /usr/local/myfile.txt 
    mode: put 

我想添加s3_url選項如果satifies條件sample_var = myapp.If它亙古不變的satify它不會有加s3_url

- name: Simple PUT operation 
    s3: 
     bucket: mybucket 
     object: /my/desired/key.txt 
     src: /usr/local/myfile.txt 
     mode: put 
     s3_url: "s3my url"------if it satisfies sample_var=myapp 

如何滿足我的條件需要將此選項添加到可信模塊時,我如何在這裏使用jinja?

在此先感謝..

回答

4

您可能想了解omitting parameters

- name: Simple PUT operation 
    s3: 
    bucket: mybucket 
    object: /my/desired/key.txt 
    src: /usr/local/myfile.txt 
    mode: put 
    s3_url: "{{ 's3my_url' if sample_var == 'myapp' else omit }}" 
+0

假設我們現在需要在設置條件像這樣s3_url:「{{ 's3my_url' 如果{{sample_var}} = = {{myapp}} else else}}「,它不會執行。在設置條件時,我們可以處理這種情況嗎? – jake

+0

語法與我發佈的完全一樣,不要使用嵌套大括號。如果'myapp'是一個變量而不是一個文字字符串,則使用不帶單引號的'myapp'。 –

+0

它的工作原理...謝謝你:-) – jake

相關問題