Answers: <p>I think this <em>might</em> be as easy as adding a sleep with the value of seconds you'd like to wait before rebooting. Also, since Ansible runs in parallel by default, we'll have to specify that we only want it to run as one process (what Ansible calls forks) instead of the default of 5. So, like this:</p>
  
  <pre><code>ansible -i inventory nodes -a "sleep 30 &amp;&amp; /sbin/reboot" -f 1
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2020-01-22T20:12:35.177Z
Answers: I also really like this one because you can tune how long it waits. Which answers my original question. I did pick @Zeitounator's answer because I am all about that module though. Great answers!
Answers: David West
Answers: CC BY-SA 4.0
Answers: 2020-01-23T07:23:03.300Z
Answers: @DavidWest Note that the module has options to tune different delays, and that ansible allows you to [async and poll](https://docs.ansible.com/ansible/latest/user_guide/playbooks_async.html) as well.
Answers: Zeitounator
Answers: CC BY-SA 4.0
Answers: 2020-01-21T19:06:20.673Z
Answers: 2020-01-21T19:06:20.673Z
Answers: Argyle
Answers: <p>@Argyle explained the <code>--fork 1</code> trick to achieve a serial run.</p>
  
  <p>I suggest you have a look at the <a href="https://docs.ansible.com/ansible/latest/modules/reboot_module.html" rel="noreferrer"><code>reboot</code> module</a> that might be better suited than running a command directly. </p>
  
  <p>A quick example that will reboot all your nodes one by one waiting for each to be fully booted before moving to the next one.</p>
  
  <pre><code>ansible -i inventory nodes --forks 1 -m reboot 
  </code></pre>
  
  <p>Pass needed parameters to the module depending on your requirements with the <code>-a</code> option.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-01-22T18:02:50.667Z
Answers: +1 for the `reboot` module. I wasn't aware it waited until the machine came back online. Good to know!
Answers: Argyle
Answers: CC BY-SA 4.0
Answers: 2020-01-21T22:42:56.963Z
Answers: 2020-01-21T22:42:56.963Z
Answers: Zeitounator
Body: <p>How do I go through all hosts in an Ansible inventory in serial with an Ansible ad-hoc and reboot servers with a specified number of seconds in between each reboot?</p>
  
  <p>I am looking for something similar to:
  <code>ansible -i inventory nodes -a "/sbin/reboot"</code> </p>
  
  <p>It should have a pause and run in serial.</p>
  
Tags: <ansible>
Title: Ansible ad-hoc command to reboot servers in serial with a pause
UserDisplayName: David West
ThreadText: # Ansible ad-hoc command to reboot servers in serial with a pause
  
  (Asked by: username_0 on 2020-01-21)
  
  How do I go through all hosts in an Ansible inventory in serial with an Ansible ad-hoc and reboot servers with a specified number of seconds in between each reboot?
  
  I am looking for something similar to:
  `ansible -i inventory nodes -a "/sbin/reboot"`
  
  It should have a pause and run in serial.
  
  **Tags:** ansible
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2020-01-21. Score: 5 | Accepted answer
  
  @username_1 explained the `--fork 1` trick to achieve a serial run.
  
  I suggest you have a look at the [`reboot` module](https://docs.ansible.com/ansible/latest/modules/reboot_module.html) that might be better suited than running a command directly.
  
  A quick example that will reboot all your nodes one by one waiting for each to be fully booted before moving to the next one.
  
  ```
  ansible -i inventory nodes --forks 1 -m reboot 
  
  ```
  
  Pass needed parameters to the module depending on your requirements with the `-a` option.
  
  > **Comments:**
  > **username_1**: +1 for the `reboot` module. I wasn't aware it waited until the machine came back online. Good to know!  
  
  ---
  
  ### Answer by username_1 on 2020-01-21. Score: 2
  
  I think this *might* be as easy as adding a sleep with the value of seconds you'd like to wait before rebooting. Also, since Ansible runs in parallel by default, we'll have to specify that we only want it to run as one process (what Ansible calls forks) instead of the default of 5. So, like this:
  
  ```
  ansible -i inventory nodes -a "sleep 30 && /sbin/reboot" -f 1
  
  ```
  
  > **Comments:**
  > **username_0**: I also really like this one because you can tune how long it waits. Which answers my original question. I did pick @username_2's answer because I am all about that module though. Great answers!  
  > **username_2**: @username_0 Note that the module has options to tune different delays, and that ansible allows you to [async and poll](https://docs.ansible.com/ansible/latest/user_guide/playbooks_async.html) as well.  
  
  ---
  
  