You were almost there!

On Fri, 26 Mar 2021 at 06:26, Clint Denham <[email protected]> wrote:
>
> The main point of this I am having difficulty in using ternary in
conjunction with a variable and would like to see if this is even possible?
The ternary doesn't seem to like the use of variable substitution inside
its statements - at least how I'm using them.
>
> This is the list I'm trying to create
>
> ports_list: "{{ ports_list|default([]) + [{'port-name':
inventory_hostname + (place_index > 1) |
ternary('1.{{place_index}}','_mgmt')}] }}"

Inside ternary you are already in jinja mode, so  drop the curly braces,
and concatenate with a tilde:

ports_list: "{{ ports_list|default([]) + [{'port-name': inventory_hostname
+ (place_index > 1) | ternary('1.' ~ place_index,'_mgmt')}] }}"

But, the index starts at zero. This should give you want you want:

ports_list: "{{ ports_list|default([]) + [{'port-name': inventory_hostname
+ (place_index > 0) | ternary('1.' ~ place_index,'_mgmt')}] }}"

--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAL8fbwPZTqgGmdNB8PEko9vfGEXV%3D98tKUppsxPzarNJ0YSmUA%40mail.gmail.com.

Reply via email to