# Check if computers are off before action

**URL:** <https://forum.ansible.com/t/check-if-computers-are-off-before-action/13095>\
**Category:** Ansible Project\
**Created:** [July 10, 2013, 9:47am UTC](https://forum.ansible.com/t/check-if-computers-are-off-before-action/13095 "2013-07-10T09:47:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francois\_Legrand](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@Francois\_Legrand](https://forum.ansible.com/u/Francois_Legrand)\
**Post date:** [July 10, 2013, 9:47am UTC](https://forum.ansible.com/t/check-if-computers-are-off-before-action/13095/1 "2013-07-10T09:47:07Z")

</div>

Hi all,  
I use ansible to shutdown some computer. I need to do it in a certain order.  
My point is that I would like to check first if some machines are really off before stopping a second group of computers.

More specifically, I have two pools in my hosts file : computing-servers and storage-servers  
I want to shutdown computing server AND BE SURE that they are all off before shutting down the storage-servers.

Any idea how I can do that ?

Thanks for your help.  
F.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [July 10, 2013, 9:52am UTC](https://forum.ansible.com/t/check-if-computers-are-off-before-action/13095/2 "2013-07-10T09:52:44Z")

</div>

​How would you check that manually (without ansible)?​  
Then we can see how you can implement that check in ansible.

---

<div class="post-metadata">

**Author:** ![GW1](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@GW1](https://forum.ansible.com/u/GW1)\
**Post date:** [July 10, 2013, 9:53am UTC](https://forum.ansible.com/t/check-if-computers-are-off-before-action/13095/3 "2013-07-10T09:53:09Z")

</div>

Hi,

Maybe the `wait_for` module with with\_items can help.

Greetings,  
gw

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [July 10, 2013, 10:01am UTC](https://forum.ansible.com/t/check-if-computers-are-off-before-action/13095/4 "2013-07-10T10:01:01Z")

</div>

​He want to be sure the server is halted, wait\_for probably just checks  
some service port like ssh, which doesn't say if the machine is powered of.  
IMHO he'll need some out of band way to check that.​

---

<div class="post-metadata">

**Author:** ![benno\_joy](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@benno\_joy](https://forum.ansible.com/u/benno_joy)\
**Post date:** [July 10, 2013, 10:02am UTC](https://forum.ansible.com/t/check-if-computers-are-off-before-action/13095/5 "2013-07-10T10:02:53Z")

</div>

Hi Francois,

I am not sure what the hardware is , but if it supports IPMI , probably you can use ipmi commands or write up an IPMI module to do the same

Regards,  
Benno

---

<div class="post-metadata">

**Author:** ![Francois\_Legrand](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@Francois\_Legrand](https://forum.ansible.com/u/Francois_Legrand)\
**Post date:** [July 10, 2013, 10:10am UTC](https://forum.ansible.com/t/check-if-computers-are-off-before-action/13095/6 "2013-07-10T10:10:20Z")

</div>

Using bash I would do a function like :

function is\_alive {  
ping -w 1 $1 \>/dev/null  
RETVAL=$?  
if [$RETVAL -eq 0]; then  
return 0  
else  
return 1  
fi  
}

and test return for each machine in the pool.

---

<div class="post-metadata">

**Author:** ![Francois\_Legrand](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@Francois\_Legrand](https://forum.ansible.com/u/Francois_Legrand)\
**Post date:** [July 10, 2013, 10:14am UTC](https://forum.ansible.com/t/check-if-computers-are-off-before-action/13095/7 "2013-07-10T10:14:33Z")

</div>

Sure I could use IPMI… for the computers which support it (but unfortunatey not all of them).  
And the other point is that all my pools are already defined in ansible, so it would be cool to use them directly from ansible.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [July 10, 2013, 11:25am UTC](https://forum.ansible.com/t/check-if-computers-are-off-before-action/13095/8 "2013-07-10T11:25:22Z")

</div>

ipmi module ++

---

<div class="post-metadata">

**Author:** ![Francois\_Legrand](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@Francois\_Legrand](https://forum.ansible.com/u/Francois_Legrand)\
**Post date:** [July 10, 2013, 3:39pm UTC](https://forum.ansible.com/t/check-if-computers-are-off-before-action/13095/9 "2013-07-10T15:39:17Z")

</div>

Finally, I found a way to do it.  
I juste run “ansible computing-servers --list-hosts” into a bash script and use the return to ping the machines one by one. Thus when they are all down, I can shutdown the storage-servers.  
F.
