How to start Ray cluster head node with ansible?

Hello folks,

I’m using ansible to deploy Ray cluster. I’m initializing head node as following:

- name: Start Ray on head node
ansible.builtin.command: ray start --head --port=6379
environment:
PATH: /opt/anaconda3/bin

register: result

I printed the result and it looks fine. But when I run “ray status” in bash, it shows “Could not find any running Ray instance” error. Also, I tried typing “ray start --head --port=6379” directly in bash, everything is fine.

So why these give different result? What’s the difference between the bash that I use and the one ansible.builtin.command uses?

Hello,

Have you tried using shell instead of command?

From shell docs:

It is almost exactly like the command module but runs the command through a shell (/bin/sh) on the remote node.

From command docs:

The command(s) will not be processed through the shell, so variables like $HOME and operations like “<”, “>”, “|”, “;” and “&” will not work. Use the shell module if you need these features.

Luca

Hello folks,

I'm using ansible to deploy Ray cluster. I'm initializing head node as following:

/ - name: Start Ray on head node/
/ ansible.builtin.command: ray start --head --port=6379/
/ environment: /
/ PATH: /opt/anaconda3/bin/
/ register: result/

I printed the result and it looks fine. But when I run "ray status" in bash, it shows "Could not find any running Ray instance" error. Also, I tried typing "ray start --head --port=6379" directly in bash, everything is fine.

So why these give different result? What's the difference between the bash that I use and the one ansible.builtin.command uses?

I think the "command" module doesn't use a shell at all, it executes the command from a Python skript.
That also means it doesn't read any of the bash configuration files, thus relevant environment variables
might be missing. Also check whether the task above uses the same user as the direct bash invocation.

Regards
          Racke

Hello guys,

Thanks for your reply! I tried shell module and it’s still not working. I’m currently using

- name: Start ray on headnode
become: false
delegate_to: 127.0.0.1
ansible.builtin.command: ssh ubuntu@{{floating_ip}} ‘export PATH=/opt/anaconda3/bin:$PATH; ray start --head --port=6379’

and it works fine for now. Free free to let me know if any elegant solution!

Best,
Joey