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

404 views
Skip to first unread message

vinayak sawant

unread,
Mar 30, 2023, 1:59:19 PM3/30/23
to ansible...@googlegroups.com
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.

Kind Regards
Vinayak Sawant

Rick Fee

unread,
Mar 30, 2023, 2:02:23 PM3/30/23
to ansible...@googlegroups.com
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)

--
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/CAM5Hc_jRPxG41%2BsfTFwm7mX-J1tLSzACBrG%3D5qbwg7QXgqqHBQ%40mail.gmail.com.

Deepanjan Acharya

unread,
Apr 3, 2023, 1:45:29 AM4/3/23
to ansible...@googlegroups.com, vinayak....@gmail.com
You could use a sleep task between this two tasks and assign 120sec sleep time.

Example: using builtin wait module

- 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”.




--

vinayak sawant

unread,
Apr 3, 2023, 3:42:59 AM4/3/23
to Deepanjan Acharya, ansible...@googlegroups.com
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.
Kind Regards
Vinayak Sawant

Dick Visser

unread,
Apr 3, 2023, 5:00:50 AM4/3/23
to ansible...@googlegroups.com
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),
then that supports the "post_reboot_delay" parameter (as mentioned in
a previous answer). That will do what (you say) you need.

Dick

vinayak sawant

unread,
Apr 3, 2023, 9:22:02 AM4/3/23
to ansible...@googlegroups.com
Hello Visser

Below is my playbook


image.png

anisble_uptime_seconds does not work for me.


Kind Regards
Vinayak Sawant


Antony Stone

unread,
Apr 3, 2023, 9:29:07 AM4/3/23
to ansible...@googlegroups.com
On Monday 03 April 2023 at 15:21:34, vinayak sawant wrote:

> anisble_uptime_seconds does not work for me.

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

Try simply "ansible_uptime_seconds >= '120'"


Antony.

--
Too many people spend money they haven't earned
to buy things they don't want,
to impress people they don't like.

- Will Rogers

Please reply to the list;
please *don't* CC me.

Deepanjan Acharya

unread,
Apr 3, 2023, 9:42:36 AM4/3/23
to ansible...@googlegroups.com
I guess you need to use gather_facts: true to be able to use the up time function here.

Thanks

vinayak sawant

unread,
Apr 3, 2023, 9:53:30 AM4/3/23
to ansible...@googlegroups.com



Hello ALL
ansible.builtin.pause:
This module worked for me as shown below
image.png

image.png


@Deepanjan Acharya : By default gather_facts is enabled untill i specify it as false.


Will update the thread post execution.



Kind Regards
Vinayak Sawant


vinayak sawant

unread,
Apr 3, 2023, 10:28:58 AM4/3/23
to ansible...@googlegroups.com

@Antony Stone : "ansible_uptime_seconds >= '120'" is not working as shown below.

image.png
image.png




Kind Regards
Vinayak Sawant

Antony Stone

unread,
Apr 3, 2023, 10:48:55 AM4/3/23
to ansible...@googlegroups.com
On Monday 03 April 2023 at 16:28:31, vinayak sawant wrote:

> @Antony Stone : "ansible_uptime_seconds >= '120'" is not working as shown
> below.

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

--
What do you call a dinosaur with only one eye? A Doyouthinkesaurus.

vinayak sawant

unread,
Apr 3, 2023, 11:07:13 AM4/3/23
to ansible...@googlegroups.com
i checked both ways with string and without string as well it did not work.


Kind Regards
Vinayak Sawant

Dick Visser

unread,
Apr 3, 2023, 12:04:18 PM4/3/23
to ansible...@googlegroups.com
Hi
I just confirmed that this super simple task does exactly what you need:

- name: reboot and wait a bit
reboot:
post_reboot_delay: 120
become: true

No need to fiddle with additional tasks and conditions.
> --
> 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/CAM5Hc_h91FL1mj7%3DKxs%2BEjU5shpN_i_vO2PNq%2B%3DFuWr9DObvJQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages