Specifying which node you want to reboot is done using a targetting pattern. This can be a single node or a group of nodes defined in the inventory. In your case, you are targetting only node1
.
You need to execute the Ansible playbook from somewhere. It's not quite clear from your question whether the Slurm head node is also the Ansible controller (the machine which is executing ansible-playbook
.
Let's assume that is the case - that the Ansible controller is also the Slurm head node. As such, your playbook as it currently stands will work.
Assuming that the head node / Ansible controller has access to the inventory, it targets a single node and reboots it.
Now, let's consider this case:
... when the playbook is executed outside the head-node...
In this case, the Ansible controller is no longer the head node, but some other machine. This could be any machine, even a machine outside of the Slurm cluster. It could also be one of the worker nodes itself. The only constraints are:
- It must have an environment that can run
ansible-playbook
- It must have access to the inventory
- It must have permission to connect to the targetted host, and the user connecting must have
sudo
rights (since you use become
).
- And of course, you need some way of triggering it...
If these conditions are satisfied, you can use the exact same playbook.
However, since you're only executing a single task, I would suggest not running a playbook at all, but an ad-hoc task. The documentation even has an example for your exact use case:
$ ansible node1 -u team -b -a "/sbin/reboot"
If you want to use the reboot
module:
ansible node1 -u team -b -m reboot -a "reboot_timeout=300"
If your inventory is in a file, you can pass it with the -i
flag.