1

I looking to execute a simple reboot via Ansible using its playbook

- name: Worker-node Reboot
  hosts: node1
  gather_facts: no
  remote_user: team
  become: true
 
  tasks:
    - name: Reboot the machine (Wait for 5 min)
      reboot:
        reboot_timeout: 300

How do I specify reboot for a worker node in Ansible's inventory for a Slurm queue when the playbook is executed outside the head-node?

1 Answer 1

0

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:

  1. It must have an environment that can run ansible-playbook
  2. It must have access to the inventory
  3. It must have permission to connect to the targetted host, and the user connecting must have sudo rights (since you use become).
  4. 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.

1
  • Thank you very much targeting patterns are the answer. I apologise for the question not being clear. Just to clarify, I'm outside the head-node (one ip address) but rebooting a node within the cluster under the head node (second ip address). Is this therefore achieved via ansible node1 -u team -m reboot -i inventory where node1 = name of worker node (targeting pattern), -i inventory contains the ip address of the headnode, -u = headnode login/full ssh address? Is targeting pattern within the inventory or (if absent) target the node name?
    – Terra
    Commented Oct 23, 2023 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.