Hello Everyone - Need your help

When I use a variable inside *ios_config* I am getting an error. The error 
message is below.

*Goal*
1. Caputre an IP addresses from "show ip interface brief" from Cisco Router
2.  Register the Output in *var_ip_address*
3.  Grep one of the IP address using 
*var_ip_address.stdout[0].split('\n')[1].split()[1]*
4. using *ios_config *configure *ntp server *
*var_ip_address.stdout[0].split('\n')[1].split()[1]*

*Problem*
The output is as expected in 
var_ip_address.stdout[0].split('\n')[1].split()[1]. 
I am good till this part

TASK [debug] 
*****************************************************************
ok: [labrtr2] => {
    "var_ip_address.stdout[0].split('\n')[1].split()[1]": "44.151.182.42"
}

When i apply the variable in to configure NTP Server using IOS_CISCO, i am 
getting the error the below error
TASK [NTP_HOSTNAME] 
************************************************************************************************************************************************
fatal: [labrtr2]: FAILED! => {*"msg": "The task includes an option with an 
undefined variable. The error was: list object has no element 1\*n\nThe 
error appears to have been in '/software/RB/NAT_1.yml': line 23, column 7, 
but may\nbe elsewhere in the file depending on the exact syntax 
problem.\n\nThe offending line appears to be:\n\n    - debug: 
var=var_ip_address.stdout[0]\n    - name: NTP_HOSTNAME\n      ^ here\n"}
        to retry, use: --limit @/software/RB/NAT_1.retry

*Full Script*
  tasks:
    - name: get_ip
      ios_command:
        provider: "{{ cli }}"
        commands: "show ip interface brief"
      register: var_ip_address

    - debug: var=var_ip_address.stdout[0].split('\n')[1].split()[1]

    - name: NTP_HOSTNAME
      ios_config:
        provider: "{{ cli }}"
        lines:
          - ntp server *"{{ 
var_ip_address.stdout[0].split('\n')[1].split()[1] }}"*
      register: NTP
    - debug: var=NTP

regards, RB

-- 
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/a1d5111a-198d-4054-87e8-a57a11535122n%40googlegroups.com.

Reply via email to