Created
March 31, 2023 16:05
-
-
Save wolftales/bc46a4954fd3aa2448985c1c78d679f2 to your computer and use it in GitHub Desktop.
Ansible variable conditional behavior example: if-elif-else
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Nested if-else statements that replicate the elif capability: | |
- name: set_fact based on varible | |
set_fact: | |
colour_fruit: "{{ 'green' if fruit == 'apples' else 'yellow' if fruit == 'bananas' else 'unknown' }}" | |
(A if True else B if True else C) | |
Can be nested further for additional elif's at the expense of readability | |
Source | |
HOWTO: Use Ansible to set replicate a if-elif-else variable | |
https://linuxbuff.wordpress.com/2020/05/06/howto-use-ansible-to-set-replicate-a-if-then-else-variable/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment