python - How to use nested if inside jinja2 filter -


i writing template file virtual host , dns inside file should change per environment host-name.below problem trying solve:

server {     listen 80;     charset utf-8;     server_name "{{ 'a.com if ansible_hostname='p.com' 'b.com' if   ansible_hostname= 'd.com' 'z.com' if ansible hostname 'k.com' else 'default.com' }}";     rewrite ^(.*)  https://$server_name$1 permanent; } 

how can achieve thing in template ie:

{{ 'a.com' if ansible_hostname='p.com' 'b.com' if ansible_hostname= 'd.com' 'z.com' if ansible hostname 'k.com' else 'default.com' }}" ` 

i new jinja 2 , have no idea how this. single if else statement working how can use multiple if else statement defining value of variable in file.

so after research work able crack down issue.we can

{% if ansible_hostname == 'a.com' %}  {% set server = 'b.com' %} {% elif ansible_hostname == 'c.com' %}  {% set server = 'd.com' %} {% else %}  {% set server = 'define yourself' %} {% endif %}  server {     listen 80;     charset utf-8;     server_name {{ server }};     rewrite ^(.*)  https://$server_name$1 permanent; } 

still if can show use of jinja2 filters achieving appreciated.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -