Reputation: 133
How can I implement below condition, to set value of dictionary config
in Ansible ?
Dictionary config
and variable turn_on_encryption
are both specified in same vars file.
if turn_on_encryption == true
, then:
config:
path: /var/www/html
cert_path: /path/to/certificate
protocol: https
else:
config:
path: /var/www/html
cert_path: ""
protocol: http
Upvotes: 1
Views: 579
Reputation: 17007
You could do something like below, using the if else in jinja2
:
vars:
config:
path: /var/www/html
cert_path: "{{ '/path/to/certificate' if turn_on_encryption else '' }}"
protocol: "{{ 'htpps' if turn_on_encryption else 'http' }}"
you could use too the ternary filter jinja2: ternary sample
Upvotes: 2