HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Ansible ad-hoc command to reboot servers in serial with a pause

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
rebootserverswithpauseserialcommandansiblehoc

Problem

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.

Solution

@Argyle explained the --fork 1 trick to achieve a serial run.

I suggest you have a look at the reboot module 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.

Code Snippets

ansible -i inventory nodes --forks 1 -m reboot

Context

StackExchange DevOps Q#10542, answer score: 5

Revisions (0)

No revisions yet.