2017-04-20 56 views
0

根據目錄是否存在,我需要在我的httpd.conf模板中包含if語句。 這裏是我迄今爲止在ansible jinja模板中定義os_path

{% if ansible_distribution_major_version > 7 and os.path.exists ("/opt/myapp/testapp") %}Include conf/vhost.conf{% endif %} 

我得到的操作系統是不確定的錯誤,當我運行任務。任何想法我做錯了什麼?

回答

1

你不能在Jinja2表達式中編寫任意的Python代碼。

運行Ansible stat模塊和註冊結果在模板之前,並使用此結果,而不是os.path.exists

+0

謝謝。不知道爲什麼我從來沒有想到這一點。 :) – crusadecoder