# How to start Ray cluster head node with ansible?

**URL:** <https://forum.ansible.com/t/how-to-start-ray-cluster-head-node-with-ansible/35458>\
**Category:** Ansible Project\
**Created:** [July 3, 2021, 4:36am UTC](https://forum.ansible.com/t/how-to-start-ray-cluster-head-node-with-ansible/35458 "2021-07-03T04:36:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joey\_Cheng](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@Joey\_Cheng](https://forum.ansible.com/u/Joey_Cheng)\
**Post date:** [July 3, 2021, 4:36am UTC](https://forum.ansible.com/t/how-to-start-ray-cluster-head-node-with-ansible/35458/1 "2021-07-03T04:36:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Luca\_remix\_tj\_Lorenz](https://avatars.discourse-cdn.com/v4/letter/l/ea666f/32.png) [@Luca\_remix\_tj\_Lorenz](https://forum.ansible.com/u/Luca_remix_tj_Lorenz)\
**Post date:** [July 3, 2021, 5:39am UTC](https://forum.ansible.com/t/how-to-start-ray-cluster-head-node-with-ansible/35458/2 "2021-07-03T05:39:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [July 3, 2021, 3:10pm UTC](https://forum.ansible.com/t/how-to-start-ray-cluster-head-node-with-ansible/35458/3 "2021-07-03T15:10:12Z")

</div>

> 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  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Joey\_Cheng](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@Joey\_Cheng](https://forum.ansible.com/u/Joey_Cheng)\
**Post date:** [July 3, 2021, 6:32pm UTC](https://forum.ansible.com/t/how-to-start-ray-cluster-head-node-with-ansible/35458/4 "2021-07-03T18:32:00Z")

</div>

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
