I am assuming you want to split a string and set the value of that to a
variable, then no need to use jinja templates

```
---
- hosts: localhost
  gather_facts: no
  vars:
    name: "ab:hi:je:ee"
  tasks:
    - name: Print variable
      set_fact:
         my_var: "{{ (name.split(':') | default(''))[2] }}"
    - debug:
         msg: "{{ my_var }}"
```

On Thu, Jul 7, 2022 at 1:55 PM gomz arvind <[email protected]> wrote:

> ---
>  - name: Cisco NXOS
>    hosts: all
>    connection: network_cli
>    gather_facts: false
>
>    vars:
>
>      - cmdlist: sh clock
>      - ansible_python_interpreter: /usr/bin/python3
>      - ansible_network_os: nxos
>      - project:
>
>    tasks:
>
>      - name: Execute command
>        nxos_command:
>         commands: "{{ cmdlist }}"
>        register: output
>
>      - set_fact:
>          arr: "{{ output.stdout_lines[0][1].split() }}"
>
>      - debug:
>           msg: "{{ arr[0] }}"
>
>      - name: print variable
>        set_fact:
>          my_string_var: "{{ arr[0].split(':') | default('') }}"
>
>      - debug:
>        #  msg: "{{my_string_var.pop(2)}}"
>          msg: |
>               {*% set project = my_string_var.pop(2) %}*
> plz find the above example
> On Thursday, July 7, 2022 at 10:16:42 AM UTC+5:30 Abhijeet Kasurde wrote:
>
>> Could you please provide more context, examples, error logs, or use case?
>> The amount of information you provided is too little to answer anything.
>>
>> On Wed, Jul 6, 2022 at 2:39 PM gomz arvind <[email protected]> wrote:
>>
>>> Hi team,
>>>
>>> can i know the actual usage of % set with ansible
>>>
>>> --
>>> 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/ab46e6f4-f7bc-4ea9-a2b6-44acd3a1a41dn%40googlegroups.com
>>> <https://groups.google.com/d/msgid/ansible-project/ab46e6f4-f7bc-4ea9-a2b6-44acd3a1a41dn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>> --
>> 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/0e9d4455-17f9-494e-96ae-b8344b18681an%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/0e9d4455-17f9-494e-96ae-b8344b18681an%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
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/CAFwWkHoT7M-zfAMs%2BTq7dn%3Dt4%2BLRMoGEMTdT6zW%2Br2saWTrVjg%40mail.gmail.com.

Reply via email to