Another easy solution - but you need to know value to drop before hand

    - name: Print variable
      set_fact:
        new_name: "{{ name.split(':') | reject('search', 'hi') }}"
      vars:
        name: "ab:hi:je:et"

On Fri, Jul 8, 2022 at 12:48 PM Abhijeet Kasurde <[email protected]>
wrote:

> You can remove nth element like - like in following case I am removing 2nd
> element
>
>     - name: Print variable
>       set_fact:
>         my_new_list: |
>             {% set result = name.split(':') %}
>             {% set _ = result.pop(2) %}
>             {{ result }}
>
>
>
> On Thu, Jul 7, 2022 at 11:37 PM gomz arvind <[email protected]>
> wrote:
>
>> @abhijeet and @brian ..thanks for ur responses
>>
>> @abhijeet- I was trying to remove a nth element from the array..so I have
>> tried with popup
>>
>> @brian : this is my understanding from ur tips..correct me if I am wrong
>>  {% set var =value %}
>> should we consider var is used only once if we use %.?
>>
>>  if  we use {{ set var = value }} jinja syntax, we can use it through the
>> playbook.
>> can u plz give me examples for both ?
>>
>>
>>
>> On Thursday, July 7, 2022 at 8:04:00 PM UTC+5:30 Brian Coca wrote:
>>
>>> To further explain, {% set var =value %} will only have an effect
>>> within that template, that does not create/update ansible variables.
>>> So while it does 'work' , you should really only use it inside a full
>>> jinja2 template.
>>>
>>>
>>> --
>>> ----------
>>> Brian Coca
>>>
>>> --
>> 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/ce6031e2-2715-4291-b6d1-19f66c3e896bn%40googlegroups.com
>> <https://groups.google.com/d/msgid/ansible-project/ce6031e2-2715-4291-b6d1-19f66c3e896bn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
> Thanks,
> Abhijeet Kasurde
>


-- 
Thanks,
Abhijeet Kasurde

-- 
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/CAFwWkHpFOU%2BEKA_8bTNwziCYjeifaQ3Y0eVwBEC86QogQg0%2BRQ%40mail.gmail.com.

Reply via email to