Those variables are scoped to a host, so they're not available to other hosts. A common trick is to assign them to a dummy host and access them that way.
On Thu, 8 Jul 2021 at 08:53, Charles Daniel <[email protected]> wrote: > When i try to use/inoke on another task, i get error as sec_tunnel_ip is > undefined. > > On Thursday, July 8, 2021 at 12:22:06 PM UTC+5:30 Charles Daniel wrote: > >> >> Team, >> >> I would like to use the variable i got from one ansible task to another >> task where hosts are different. >> >> Please help me use the variable to use it on another task!! >> >> --- >> >> - name: Get the primary router tunnel ip address >> hosts: primary >> gather_facts: false >> connection: local >> tags: >> - "get_sec_tunnel_ip" >> tasks: >> - name: Obtain primary tunnel interface ip address >> ios_command: >> commands: >> - "show interface tunnel1 | sec Internet address" >> register: output >> - debug: >> msg: "{{ output.stdout}}" >> - set_fact: >> intf: | >> - {{output.stdout | >> map('regex_search','(([0-9]+(.)[0-9]+(.)[0-9]+(.)[0-9]+))') | list }} >> register: sec_tunnel_ip >> - debug: >> msg={{ sec_tunnel_ip }} >> >> - name: Display router tunnel ip address from this task >> hosts: secondary >> gather_facts: false >> connection: local >> tags: >> - "use_output" >> tasks: >> - name: Display primary tunnel interface ip address >> - debug: >> msg: "{{ sec_tunnel_ip }}" >> >> -- > 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/1daafd88-3c14-456a-bb94-e6f7f3ba8748n%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/1daafd88-3c14-456a-bb94-e6f7f3ba8748n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Sent from a mobile device - please excuse the brevity, spelling and punctuation. -- 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/CAL8fbwNgLOFRTcqwK%3D4cVwBuheu4f00k0LdjY2o8cwa_S3xH3Q%40mail.gmail.com.
