12 ms·
I use it to conditionally add elements to array or dict in group_vars, real life example: aws_tags_pio: RoleImage: "pio" aws_tags_role_app_tpl: [ { Role:
by Szpadel 3y ago
I use it to conditionally add elements to array or dict in group_vars, real life example:
aws_tags_pio:
RoleImage: "pio"
aws_tags_role_app_tpl: [
{ Role: "app" },
"{{ (mageops_pio_worker_enable and not mageops_pio_worker_dedicated_asg) | ternary(aws_tags_pio, {}) }}"
]
aws_tags_role_app: "{{ aws_tags_role_app_tpl | combine }}"
https://github.com/mageops/ansible-infrastructure/blob/5dcc321c8d2a918afd43e2a50665ccbd1159a674/group_vars/all.yml#L83-L96 https://github.com/mageops/ansible-infrastructure/blob/5dcc3...
for array you use flatten eg
aws_security_group_persistant_rules_tpl: [
"{{ mageops_ssh_proxy_persistant | ternary(aws_security_group_persistant_rules_ssh_proxy, []) }}",
"{{ mageops_tinyproxy_persistant_enabled | ternary(aws_security_group_persistent_rules_tinyproxy, []) }}"
]
aws_security_group_persistant_rules: "{{ aws_security_group_persistant_rules_tpl | flatten }}"
this pattern really helped to clean up conditionals that normally had to be done in tasks