Grey
Grey

Reputation: 63

Unclear ansible variable formatting

When formatting variables in ansible playbooks which format should be followed? I cannot for the life of me find a straight answer for this?

environment:
    - http_proxy: "{{ {{ proxy }} if {{ proxy }} != '' else {{ ansible_local.proxy_facts.proxy }} }}"
    - http_proxy: "{{ proxys if proxy != '' else ansible_local.proxy_facts.proxy }}"

Upvotes: 0

Views: 42

Answers (1)

Vladimir Botka
Vladimir Botka

Reputation: 68074

Use ternary filter. For example

- set_fact:
    http_proxy: "{{ (proxy|length > 0)|
                     ternary(proxy, ansible_local.proxy_facts.proxy) }}"

Don't compare to empty string

Upvotes: 1

Related Questions