wait_for module doesn't work as expected with router

213 views
Skip to first unread message

Vikram S

unread,
Feb 20, 2021, 9:57:18 AM2/20/21
to Ansible Project
Hi,

I am writing a script to upgrade IOS in cisco router. After i give reload command, the next task to be executed is the below one.
This part of the playbook basically waits for the device to be reachable again on port 22. I have also added a delay of 600 seconds before it starts trying. The playbook will not progress until this device is reachable.
However this TASK doesn't execute as expected. I am getting an error. Am i doing something wrong or overlooking anything?  (username, password and host IP is defined in invetory file)

      - name: WAIT 30 MINUTES FOR DEVICE TO COME ONLINE
        wait_for:
          host: "{{ inventory_hostname }}"
          port: 22
          delay: 600
        delegate_to: localhost



root@NetworkAutomation-2:~# ansible-playbook sample28.yaml

PLAY [PLAYBOOK FOR UPGRADE TASKS] ******************************************************************************************************

TASK [WAIT 30 MINUTES FOR DEVICE TO COME ONLINE] ***************************************************************************************

fatal: [R1 -> localhost]: FAILED! => {"changed": false, "elapsed": 300, "msg": "Timeout when waiting for R1:22"}

PLAY RECAP *****************************************************************************************************************************
R1                         : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0


Thanks,
Vikram

Stefan Beke

unread,
Feb 22, 2021, 9:51:48 AM2/22/21
to Ansible Project
wait_for have timeout, by default 300s.

wait_for:
    timeout: 800

Message has been deleted

Vikram S

unread,
Feb 22, 2021, 10:53:05 AM2/22/21
to Ansible Project
Hi,

The issue is that device is online and reachable even before the timeout of 300 secs is reached. Yet this command doesn't work. 
I know it's reachable because i never restarted the device, i was just testing this TASK.

Thanks,
Vikram

Dick Visser

unread,
Feb 22, 2021, 11:49:18 AM2/22/21
to ansible...@googlegroups.com
Did you see the last example on
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/wait_for_module.html#examples
?
Check if that is your problem.
> --
> 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 ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f94ceb50-1481-472a-a6da-08f154443238n%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Vikram S

unread,
Feb 22, 2021, 1:49:59 PM2/22/21
to Ansible Project
Hi Dick,

Thanks for pointing, i tried what was given on the examples but still getting same error.
Ansible documentation suggests to use ProxyCommand instrad of delegate_to and i suspect that may be the cause of this issue.
As per documentation, below is the Proxycommand syntax recommended (The network module will now connect to the network device by first connecting to the host specified in ansible_ssh_common_args, which is bastion01 in the above example). But iam not sure what is bastion01 or what i should replace it with in my script.

Below is the playbook output when run with 4 verbosity and error only heitens my above suspicion.
[nxos:vars] ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -q bastion01"'
I ran the playbook with 4 verbosity and below is the error logs. 

 File "/usr/lib/python2.7/socket.py", line 557, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
fatal: [R1 -> localhost]: FAILED! => {
    "changed": false,
    "elapsed": 300,

Regards,
Vikram

Reply all
Reply to author
Forward
0 new messages