r/ansible•
JoeReally

Share your input/playbook on how you shutdown your homelab?

Last night the house lost power. I’d like to have a playbook I can kick off from my phone (via ssh script to a server) that would gracefully shutdown all my servers while the UPSes are online. Does anyone have something similar they’d like to share or input on my plan below?

I believe what I should do is:

  • Docker swarm: stop all services OR pause all nodes.
    ; goal here is to do this before draining so services will not try and restart on other nodes
    ; not sure which method is better, also not sure how to stop “all” services instead of a specific list/loop
  • Docker swarm: drain all worker nodes
  • Docker swarm: drain all manager nodes
  • Docker swarm: shutdown all nodes
    ; most graceful way? Is there an Ansible shutdown command? I only see reboot. Shell command?
  • Docker stand-alones (if any): drain, then shutdown
  • Physical servers: shutdown
    ; any command to execute before shutdown to make it more “graceful”?
  • DNS: shutdown
  • NAS: shutdown

Any other steps I should add? Thanks.

Posted Apr 21, 2020, 4:50 PM UTC

23
Grunchlk•

Shutdown all VMs.

Put your cluster in global maintenance mode.

Shutdown all hypervisor hosts that aren't running the engine.

Switch to console and shutdown the engine.

Detach storage then proceed with NAS shutdown.

2
anoland•

Upsd and network ups tools can do all the work for you.

I have upsd running on my nas server and NUT agents on each server listening for shut down messages. Anytime the ups loses power it shuts everything down gracefully.

A primary reason to not rely ssh to execute shutdown scripts is that likely if your house doesn't have power, neither does your internet connection. Even if you put your modem/router on the ups, everything outside your house could be down.

1
JoeReallyOP•

Well the ups trigger would be the next step once I get a playbook together, hence the question.

Not too worried about being unable to do it from outside the house yet since Corona has me home so much and I work from home, but yes a ups trigger would be the next part of this.

1