Thanks Pushparaj for your help. *set_fact *is the savior here. It works by
using the variable captured under set_fact.
Thanks again for mind share and your comment solved my requirement. Have a
nice time ahead. :)
On Sunday, May 30, 2021 at 7:01:34 AM UTC+5:30 rajthecomputerguy wrote:
> Try -- set_fact the grep output and try to call the variable in ios_config
>
> set_fact:
> desired_ntp: {{ var_ip_address.stdout[0].split('\n')[1].split()[1] }}
>
> On Sun, May 30, 2021 at 12:25 AM R.B. Kumar <[email protected]> wrote:
>
>> 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
>>
>> <https://groups.google.com/d/msgid/ansible-project/a1d5111a-198d-4054-87e8-a57a11535122n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
>
> Thanks,
>
> Pushparaj G
>
>
--
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/36e618aa-40e2-4014-b408-044f915ab458n%40googlegroups.com.