Automate shutdown command via Ansible playbook

2,151 views
Skip to first unread message

xinhua...@gmail.com

unread,
Mar 16, 2022, 3:51:30 PM3/16/22
to Ansible Project
I'm using ansible 2.9. There is no shutdown module available.

I need to automate shutdown command via Ansible playbook. The target hosts are different distributions of CentOS servers - 7 or 6. When I ran the playbook to shutdown them, the execution will hang forever for one of CentOS 7 servers. I had to hit Ctrl-C. The execution stopped when example8 is down. It is CentOS 7. The example7 is CentOS 6 and does not hang forever.

inventory file:
[shutdown_300]
example1

[shutdown_301]
example2

[shutdown_302]
example3

[shutdown_303]
example4

[shutdown_304]
example5

[shutdown_305]
example6

[shutdown_306]
example7
example8

[shutdown_30:children]
shutdown_306
shutdown_305
shutdown_304
shutdown_303
shutdown_302
shutdown_301
shutdown_300

Here is the playbook:
---
- hosts: shutdown_30
  gather_facts: no

  tasks:
    - name: Shutdown order 30 
      raw: shutdown -h now
      ignore_unreachable: true
      ignore_errors: true


command to run the playbook:
ansible-playbook -i inventory shutdown.yml

Is there better way to prevent hang because the host is down?

Xinhuan

Dick Visser

unread,
Mar 16, 2022, 4:00:19 PM3/16/22
to ansible...@googlegroups.com
On Wed, 16 Mar 2022 at 20:51, xinhua...@gmail.com <xinhua...@gmail.com> wrote:
I'm using ansible 2.9. There is no shutdown module available.

Don't waste time on working around problems in unsupported software.
Instead use the energy to upgrade to something supported.





Nico Kadel-Garcia

unread,
Mar 16, 2022, 6:02:57 PM3/16/22
to ansible...@googlegroups.com
A more recent version is not published as an RPM for RHEL systems. If
you want one, I publish tools to build RPMs for it at
https://github.com/nkadel/ansiblerepo/

You probably have no use for the current ansible package. It is a very
bulky agglomeration of roughly 100 ansible collection modules, and
*all* the necessary scripts and python modules for basic ansible
operation are in the ansible-core package. I suspect that if you rip
out ansible, install ansible-core, and install the ansible collection
modules on if and when needed, you will have a much more stable
ansible setup.
Reply all
Reply to author
Forward
0 new messages