# run command on several nodes, but run another command on first node

**URL:** <https://forum.ansible.com/t/run-command-on-several-nodes-but-run-another-command-on-first-node/22152>\
**Category:** Ansible Project\
**Created:** [July 28, 2016, 2:55pm UTC](https://forum.ansible.com/t/run-command-on-several-nodes-but-run-another-command-on-first-node/22152 "2016-07-28T14:55:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kfrydrys\_ILIM](https://avatars.discourse-cdn.com/v4/letter/k/f14d63/32.png) [@kfrydrys\_ILIM](https://forum.ansible.com/u/kfrydrys_ILIM)\
**Post date:** [July 28, 2016, 2:55pm UTC](https://forum.ansible.com/t/run-command-on-several-nodes-but-run-another-command-on-first-node/22152/1 "2016-07-28T14:55:16Z")

</div>

Hi,  
I want to use ansible to start MariaDB/GaleraCluster

I need to run

1. 

**/usr/bin/mysqld\_safe --wsrep-new-cluster &**

on the one of the nodes first (there is no important it node1, or node4).

1. next I want to run  
**systemctl start mariadb**  
on every other node in the cluster (excluding node from previous step).

Can ansible can help me do this, which module?

Best regards,  
Kfrydrys

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 29, 2016, 7:59am UTC](https://forum.ansible.com/t/run-command-on-several-nodes-but-run-another-command-on-first-node/22152/2 "2016-07-29T07:59:24Z")

</div>

> Hi,  
> I want to use ansible to start MariaDB/GaleraCluster
> 
> I need to run
> 
> 1.  
> \*/usr/bin/mysqld\_safe --wsrep-new-cluster &\*

Running a program in the background like that is not recommended, and I'm not sure if it will work with Ansible.  
Best is to create a init script for it instead.

> on the one of the nodes first (there is no important it node1, or node4).
> 
> 2. next I want to run
> 
> \*systemctl start mariadb \* on every other node in the cluster (excluding  
> node from previous step).
> 
> Can ansible can help me do this, which module?

If all the hosts is in the same Ansible group, lets call the group mysqlcluster, you could do something like this.

Pseudocode

- task1  
&nbsp;&nbsp;&nbsp;when: inventory\_hostname == mysqlcluster[0]

- task2  
&nbsp;&nbsp;&nbsp;when: inventory\_hostname != mysqlcluster[0]

mysqlcluster[0] is the first host in the group.
