- roles - consul - vars/main.yml In main.yml use:
consul_is_server: {{ true if consul_server is defined else false }} playbook:
- hosts: consul-server roles: - consul vars: consul_server: true Mistake:
consul_is_server: {{ "true" if consul_server is defined else "false" }} ^ We could be wrong, but this one looks like it might be an issue with missing quotes. Always quote template expression brackets when they start a value. For instance: with_items: - {{ foo }} Should be written as: with_items: - "{{ foo }}" Did so:
consul_is_server: > {{ true if consul_server is defined and consul_server==true else false }} But then consul_is_server will be the string: "False" or "True." And then in the templates you have to cast in bool :
"server": {{ "true" if consul_is_server |bool else "false" }} Can I vars write the conditions check in vars so that I don’t have to do it in the template later?
"{{ true if consul_server is defined else false }}"? - Nick Volynkin ♦defined, it is necessary that it still betrue- Suvitruf ♦