Re: [ansible-project] what s the use of % set with ansible

2022-07-08 Thread Abhijeet Kasurde
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 wrote: > You can remove

Re: [ansible-project] what s the use of % set with ansible

2022-07-08 Thread Abhijeet Kasurde
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

Re: [ansible-project] what s the use of % set with ansible

2022-07-07 Thread gomz arvind
@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

Re: [ansible-project] what s the use of % set with ansible

2022-07-07 Thread Brian Coca
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

Re: [ansible-project] what s the use of % set with ansible

2022-07-07 Thread Abhijeet Kasurde
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(':') |

Re: [ansible-project] what s the use of % set with ansible

2022-07-07 Thread gomz arvind
--- - 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:

Re: [ansible-project] what s the use of % set with ansible

2022-07-06 Thread Abhijeet Kasurde
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 wrote: > Hi team, > > can i know the actual usage of % set with ansible > > -- > You received this

[ansible-project] what s the use of % set with ansible

2022-07-06 Thread gomz arvind
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 ansible-project+unsubscr...@googlegroups.com. To