I am a writing a template file for virtual host and DNS inside the file should change as per environment host-name.Below is problem i am trying to 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 is 'k.com' else 'default.com' }}";
rewrite ^(.*) https://$server_name$1 permanent;
}
How can i achieve this thing in template ie:
{{ 'a.com' if ansible_hostname='p.com' 'b.com' if ansible_hostname= 'd.com' 'z.com' if ansible hostname is 'k.com' else 'default.com' }}" `
I am new to jinja 2 and have no idea how to do this. Single if else statement is working but how can i use multiple if else statement for defining the value of a variable in the file.