1

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

Is this possible with Ansible ?
penguin
  • 133
  • 2
  • 15

1 Answers1

2

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

penguin
  • 133
  • 2
  • 15
Frenchy
  • 16,386
  • 3
  • 16
  • 39