Hello - The difference between working and not working script is given
below. Need to find out why we get "VARIABLE IS NOT DEFINED" in script-1
*NOT WORKING SCRIPT* *(SCRIPT-1)*
- name: get_ip
ios_command:
provider: "{{ cli }}"
commands: "show ip interface brief *{{ item }}*"
register: var_ip_addr_0
with_items:
- gigabitEthernet0/0/0
- debug: var="var_ip_addr_0.stdout.line[0]"
TASK [debug]
*******************************************************************************************************************************************************
ok: [labrtr2] => {
"var_ip_addr_0.stdout.line[0]": *"VARIABLE IS NOT DEFINED!"*
}
*WORKING SCRIPT (SCRIPT-2)*
- name: get_ip
ios_command:
provider: "{{ cli }}"
commands: "show ip interface brief *Gigabitethernet 0/0/0*"
register: var_ip_addr_0
- debug: var="var_ip_addr_0.stdout[0].split('\n')[1].split()[1]"
TASK [debug]
***************************************************************************************************************
ok: [labrtr2] => {
"var_ip_addr_0.stdout[0].split('\n')[1].split()[1]": *"42.151.182.42"*
}
On Friday, May 28, 2021 at 1:57:59 PM UTC+5:30 [email protected] wrote:
> So would it work if you just use stdout or is split required?
>
> If split is required, pls show me the stdout output and what you need from
> this value?
>
> On Fri, May 28, 2021, 13:48 R.B. Kumar <[email protected]> wrote:
>
>> Thank you.. Just by printing stdout, it shows all the data perfectly.
>> But when i try to grep it using split, it is showing "VARIABLE IS NOT FOUND"
>>
>> TASK [debug]
>> ***************************************************************************************************************
>> ok: [labrtr2.allmerica.com] => {
>> "var_ip_addr_0.stdout[0].split('\n')[1].split()[1]": "VARIABLE IS NOT
>> DEFINED!"
>> }
>>
>> if i remove stdout[0].split('\n')[1].split()[1]": I am getting the
>> output showing the IP address in the output
>>
>> On Friday, May 28, 2021 at 1:41:47 PM UTC+5:30 [email protected] wrote:
>>
>>> Please try to print stdout value first and see what does it contain.
>>> Stdout_lines may have your data.
>>>
>>> On Fri, May 28, 2021, 13:38 R.B. Kumar <[email protected]> wrote:
>>>
>>>> Hello All - I am using Ansible version 2.7.18
>>>>
>>>> I am trying this code to get IP address of the Cisco Router interface.
>>>> When i use {{ item }}, the IP address is not captured. Where as if i use a
>>>> static value (eg: show ip interface brief gig 0/0/0), the IP address is
>>>> captured and i can use it in the script.
>>>>
>>>> Can you help me what is the mistake here? Thanks
>>>>
>>>> - name: get_ip
>>>> ios_command:
>>>> provider: "{{ cli }}"
>>>> commands: "show ip interface brief *{{ item }}"*
>>>> register: var_ip_addr_0
>>>>
>>>> * with_items:*
>>>> * - gigabitEthernet0/0/0*
>>>>
>>>> - debug: var="var_ip_addr_0.stdout[0].split('\n')[1].split()[1]"
>>>>
>>>> But, the output of the debug shows the value is not captured.
>>>>
>>>> TASK [debug]
>>>> ***************************************************************************************************************
>>>> ok: [labrtr2.allmerica.com] => {
>>>> "var_ip_addr_0.stdout[0].split('\n')[1].split()[1]":* "VARIABLE IS
>>>> NOT DEFINED!"*
>>>> }
>>>>
>>>> PLAY RECAP
>>>> *****************************************************************************************************************
>>>> labrtr2.allmerica.com : ok=3 changed=0 unreachable=0
>>>> failed=0
>>>>
>>>> --
>>>> 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/e11452df-60f8-4f11-afa8-fe1afb2749f1n%40googlegroups.com
>>>>
>>>> <https://groups.google.com/d/msgid/ansible-project/e11452df-60f8-4f11-afa8-fe1afb2749f1n%40googlegroups.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/cc364f87-41e7-437e-a267-83ded09405c1n%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/cc364f87-41e7-437e-a267-83ded09405c1n%40googlegroups.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/b7db4561-8cf0-48f2-b4c9-82da6ef4f52an%40googlegroups.com.