Reputation: 669
I need to include an if statement in my httpd.conf template based on whether a directory exists. Here is what i have so far
{% if ansible_distribution_major_version > 7 and os.path.exists ("/opt/myapp/testapp") %}Include conf/vhost.conf{% endif %}
I get an os is undefined error when i run the task. Any idea what i am doing wrong?
Upvotes: 0
Views: 572
Reputation: 68289
You can't write arbitrary Python code inside Jinja2 expression.
Run Ansible stat
module and register result before templating and use this result instead of os.path.exists
.
Upvotes: 1