Hello - I attached the output of debug when i used {{ item }}. That is show 
ip interface brief {{ item }}. I am trying to capture the IP address in the 
output and reuse it in the script. 



TASK [debug] 
***************************************************************************************************************
ok: [labrtr2] => {
    "var_ip_addr_0": {
        "changed": false, 
        "msg": "All items completed", 
        "results": [
            {
                "_ansible_ignore_errors": null, 
                "_ansible_item_label": "gigabitEthernet0/0/0", 
                "_ansible_item_result": true, 
                "_ansible_no_log": false, 
                "_ansible_parsed": true, 
                "changed": false, 
                "failed": false, 
                "invocation": {
                    "module_args": {
                        "auth_pass": null, 
                        "authorize": null, 
                        "commands": [
                            "show ip interface brief gigabitEthernet0/0/0"
                        ], 
                        "host": null, 
                        "interval": 1, 
                        "match": "all", 
                        "password": null, 
                        "port": null, 
                        "provider": {
                            "auth_pass": null, 
                            "authorize": null, 
                            "host": null, 
                            "password": 
"VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
                            "port": null, 
                            "ssh_keyfile": null, 
                            "timeout": null, 
                            "username": 
"VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
                        }, 
                        "retries": 10, 
                        "ssh_keyfile": null, 
                        "timeout": null, 
                        "username": null, 
                        "wait_for": null
                    }
                }, 
                "item": "gigabitEthernet0/0/0", 
                "stdout": [
                    "Interface              IP-Address      OK? Method 
Status                Protocol\nGigabitEthernet0/0/0   

42.151.182.42   YES DHCP   up                    up"
                ], 
                "stdout_lines": [
                    [
                        "Interface              IP-Address      OK? Method 
Status                Protocol", 
                        "GigabitEthernet0/0/0  * 42.151.182.42 *  YES DHCP  
 up                    up"
                    ]
                ]
            }
        ]
    }
}

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/c71fcd3a-ac6c-410e-808b-7d715a5942bfn%40googlegroups.com.

Reply via email to