Oh wow! Thanks a ton! That works perfect. I hadn't seen/heard of the tilde usage yet. Lots to learn but many thanks (again) for the fix!
On Fri, Mar 26, 2021 at 12:53 AM Dick Visser <[email protected]> wrote: > 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 > <https://groups.google.com/d/msgid/ansible-project/CAL8fbwPZTqgGmdNB8PEko9vfGEXV%3D98tKUppsxPzarNJ0YSmUA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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/CAA92%3DYOWXEX9dG7E%3DQEu3%3D18cJx31GgNHVo4PWg-u1bQE-65fQ%40mail.gmail.com.
