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

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.

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

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.

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

Hello Visser

Below is my playbook

anisble_uptime_seconds does not work for me.

Kind Regards

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

Try simply "ansible_uptime_seconds >= '120'"

Antony.

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

Thanks

(attachments)

Hello ALL

ansible.builtin.pause:
This module worked for me as shown below

@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)

@Antony Stone : “ansible_uptime_seconds >= ‘120’” is not working as shown below.

(attachments)



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

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

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.