# How to wait for uptime of 2 minutes and then execute next task

**URL:** <https://forum.ansible.com/t/how-to-wait-for-uptime-of-2-minutes-and-then-execute-next-task/37830>\
**Category:** Ansible Project\
**Created:** [March 30, 2023, 5:58pm UTC](https://forum.ansible.com/t/how-to-wait-for-uptime-of-2-minutes-and-then-execute-next-task/37830 "2023-03-30T17:58:57Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinayak\_sawant](https://avatars.discourse-cdn.com/v4/letter/v/4da419/32.png) [@vinayak\_sawant](https://forum.ansible.com/u/vinayak_sawant)\
**Post date:** [March 30, 2023, 5:58pm UTC](https://forum.ansible.com/t/how-to-wait-for-uptime-of-2-minutes-and-then-execute-next-task/37830/1 "2023-03-30T17:58:57Z")

</div>

Hello Team

i am doing rolling restart for servers and it is working fine but what i need to add is when first server is rebooted and its up for 2 minutes then it should go for next server for reboot

So how can I take that uptime condition with shell in ansible playbook to proceed.

---

<div class="post-metadata">

**Author:** ![Endure\_Kona](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/endure_kona/32/391_2.png) [@Endure\_Kona](https://forum.ansible.com/u/Endure_Kona)\
**Post date:** [March 30, 2023, 6:01pm UTC](https://forum.ansible.com/t/how-to-wait-for-uptime-of-2-minutes-and-then-execute-next-task/37830/2 "2023-03-30T18:01:54Z")

</div>

should be close to this…but this is for windows…think if you put post\_reboot\_delay?

- name: DAG Node - Rebooting server Exchange has been updated, wait for MSExchangeADTopology service to come back to running until rebooting the next server.  
win\_reboot:  
reboot\_timeout: 3600  
post\_reboot\_delay: 120  
test\_command: ‘exit (Get-Service -Name MSExchangeADTopology).Status -ne “Running”’  
ignore\_errors: yes  
when: (ClusterInfo.exists == True) and (ExchangeUpdate.exists == False) and ((inventory\_hostname|upper).find(‘XU’) == -1) or (‘Reboot Required’ in ServerReboot)

---

<div class="post-metadata">

**Author:** ![Deepanjan\_Acharya](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@Deepanjan\_Acharya](https://forum.ansible.com/u/Deepanjan_Acharya)\
**Post date:** [April 3, 2023, 5:44am UTC](https://forum.ansible.com/t/how-to-wait-for-uptime-of-2-minutes-and-then-execute-next-task/37830/3 "2023-04-03T05:44:59Z")

</div>

You could use a sleep task between this two tasks and assign 120sec sleep time.

Example: using builtin wait module

```auto
- name: Sleep for 300 seconds and continue with play
  ansible.builtin.wait_for:
    timeout: 300
  delegate_to: localhost

```

Other wise you can use shell module and use command “sleep 300”.

---

<div class="post-metadata">

**Author:** ![vinayak\_sawant](https://avatars.discourse-cdn.com/v4/letter/v/4da419/32.png) [@vinayak\_sawant](https://forum.ansible.com/u/vinayak_sawant)\
**Post date:** [April 3, 2023, 7:42am UTC](https://forum.ansible.com/t/how-to-wait-for-uptime-of-2-minutes-and-then-execute-next-task/37830/4 "2023-04-03T07:42:36Z")

</div>

Thanks Deepanjan.

But here is how I can be sure my server is up or not.

If my server is not up then it will not work right

i had tried seconds from setup module but it did not work

So is there any other option to perform this task as i have to reboot server one by one not all at time.

Serial module is working for this but unable to wait for 3 min of uptime of server to restart another server.

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [April 3, 2023, 9:00am UTC](https://forum.ansible.com/t/how-to-wait-for-uptime-of-2-minutes-and-then-execute-next-task/37830/5 "2023-04-03T09:00:14Z")

</div>

You have not shared any playbooks.  
How are you doing this "rolling restart"?

If you use the reboot module  
([https://docs.ansible.com/ansible/latest/collections/ansible/builtin/reboot\_module.html](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/reboot_module.html)),  
then that supports the "post\_reboot\_delay" parameter (as mentioned in  
a previous answer). That will do what (you say) you need.

Dick

---

<div class="post-metadata">

**Author:** ![vinayak\_sawant](https://avatars.discourse-cdn.com/v4/letter/v/4da419/32.png) [@vinayak\_sawant](https://forum.ansible.com/u/vinayak_sawant)\
**Post date:** [April 3, 2023, 1:21pm UTC](https://forum.ansible.com/t/how-to-wait-for-uptime-of-2-minutes-and-then-execute-next-task/37830/6 "2023-04-03T13:21:34Z")

</div>

Hello Visser

Below is my playbook

 ![image.png](https://us1.discourse-cdn.com/ansible/original/2X/0/0d43cae2fdd5e028409510dcbcefa59afbb418c1.png)

anisble\_uptime\_seconds does not work for me.

**Kind Regards**

---

<div class="post-metadata">

**Author:** ![Antony\_Stone](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Antony\_Stone](https://forum.ansible.com/u/Antony_Stone)\
**Post date:** [April 3, 2023, 1:28pm UTC](https://forum.ansible.com/t/how-to-wait-for-uptime-of-2-minutes-and-then-execute-next-task/37830/7 "2023-04-03T13:28:44Z")

</div>

" == or =\> '120'" ???

Try simply "ansible\_uptime\_seconds \>= '120'"

Antony.

---

<div class="post-metadata">

**Author:** ![Deepanjan\_Acharya](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@Deepanjan\_Acharya](https://forum.ansible.com/u/Deepanjan_Acharya)\
**Post date:** [April 3, 2023, 1:42pm UTC](https://forum.ansible.com/t/how-to-wait-for-uptime-of-2-minutes-and-then-execute-next-task/37830/8 "2023-04-03T13:42:04Z")

</div>

I guess you need to use gather\_facts: true to be able to use the up time function here.

Thanks

> **(attachments)**
>
> ![image.png](https://us1.discourse-cdn.com/ansible/original/2X/0/0d43cae2fdd5e028409510dcbcefa59afbb418c1.png)

---

<div class="post-metadata">

**Author:** ![vinayak\_sawant](https://avatars.discourse-cdn.com/v4/letter/v/4da419/32.png) [@vinayak\_sawant](https://forum.ansible.com/u/vinayak_sawant)\
**Post date:** [April 3, 2023, 1:53pm UTC](https://forum.ansible.com/t/how-to-wait-for-uptime-of-2-minutes-and-then-execute-next-task/37830/9 "2023-04-03T13:53:04Z")

</div>

Hello ALL

```auto
ansible.builtin.pause:

```

```auto
This module worked for me as shown below

```

 ![image.png](https://us1.discourse-cdn.com/ansible/original/2X/d/d3483d34401e7e5222049eaef3a5ab88d76867c2.png)

 ![image.png](https://us1.discourse-cdn.com/ansible/original/2X/d/d69e934c8f2254db6d826ff91697987d6e2a5332.png)

@Deepanjan Acharya : By default gather\_facts is enabled untill i specify it as false.

@Antony Stone : Let me try with this option.

Will update the thread post execution.

> **(attachments)**
>
> ![image.png](https://us1.discourse-cdn.com/ansible/original/2X/0/0d43cae2fdd5e028409510dcbcefa59afbb418c1.png)

---

<div class="post-metadata">

**Author:** ![vinayak\_sawant](https://avatars.discourse-cdn.com/v4/letter/v/4da419/32.png) [@vinayak\_sawant](https://forum.ansible.com/u/vinayak_sawant)\
**Post date:** [April 3, 2023, 2:28pm UTC](https://forum.ansible.com/t/how-to-wait-for-uptime-of-2-minutes-and-then-execute-next-task/37830/10 "2023-04-03T14:28:31Z")

</div>

@Antony Stone : “ansible\_uptime\_seconds \>= ‘120’” is not working as shown below.

 ![image.png](https://us1.discourse-cdn.com/ansible/original/2X/f/fca8a57003549654df793b3a353f4071a42beb4d.png)

 ![image.png](https://us1.discourse-cdn.com/ansible/original/2X/a/ac24816e3aeb894a622d8cb8f8a4afd239393c7f.png)

> **(attachments)**
>
> ![image.png](https://us1.discourse-cdn.com/ansible/original/2X/0/0d43cae2fdd5e028409510dcbcefa59afbb418c1.png)  
> ![image.png](https://us1.discourse-cdn.com/ansible/original/2X/d/d3483d34401e7e5222049eaef3a5ab88d76867c2.png)  
> ![image.png](https://us1.discourse-cdn.com/ansible/original/2X/d/d69e934c8f2254db6d826ff91697987d6e2a5332.png)

---

<div class="post-metadata">

**Author:** ![Antony\_Stone](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Antony\_Stone](https://forum.ansible.com/u/Antony_Stone)\
**Post date:** [April 3, 2023, 2:48pm UTC](https://forum.ansible.com/t/how-to-wait-for-uptime-of-2-minutes-and-then-execute-next-task/37830/11 "2023-04-03T14:48:31Z")

</div>

I did not mean you to add the " characters - those were simply to identify the  
string I think you should use in order to confirm to ansible syntax.

Antony

---

<div class="post-metadata">

**Author:** ![vinayak\_sawant](https://avatars.discourse-cdn.com/v4/letter/v/4da419/32.png) [@vinayak\_sawant](https://forum.ansible.com/u/vinayak_sawant)\
**Post date:** [April 3, 2023, 3:06pm UTC](https://forum.ansible.com/t/how-to-wait-for-uptime-of-2-minutes-and-then-execute-next-task/37830/12 "2023-04-03T15:06:49Z")

</div>

i checked both ways with string and without string as well it did not work.

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [April 3, 2023, 4:02pm UTC](https://forum.ansible.com/t/how-to-wait-for-uptime-of-2-minutes-and-then-execute-next-task/37830/13 "2023-04-03T16:02:53Z")

</div>

Hi  
I just confirmed that this super simple task does exactly what you need:

&nbsp;&nbsp;&nbsp;&nbsp;- name: reboot and wait a bit  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reboot:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;post\_reboot\_delay: 120  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;become: true

No need to fiddle with additional tasks and conditions.
