Can ansible automate the last steps of setting up a Percona Xtra Cluster

Hello guys,

I’m new to Ansible. Could anyone please help me with my question?

I’m trying to automate the entire process of setting up a 2-node PXC. All the package installation and file configuration work have already been automated using ansible. But I’m stuck in the last steps.

Here are the remaining steps:

  1. Use ‘/etc/init.d/mysql bootstrap-pxc’ to bootstrap the cluster from node1, keep the mysql instance on node2 shut.
  2. Connect to mysql on node1 and create accounts for xtrabackup
  3. Use ‘/etc/init.d/mysql start’ to start the mysql instance on node2 and it will join the cluster automatically.

I would like to know if Ansible can control the command execution orders between different nodes. The question is actually not specific to PXC, but applies to other cluster applications where order matters.

Thanks,
Jason

Yes, this is trivial with Ansible. You can do this either as separate plays
in the same playbook, or by delegating tasks to different machines in one
play. I'd personally opt for the former because it's a more obvious what
is going on when you go back and look at it later on.

Jason Zhao <prclxzc@gmail.com> napisał:

Hello guys,

I'm new to Ansible. Could anyone please help me with my question?

I'm trying to automate the entire process of setting up a 2-node PXC.
All
the package installation and file configuration work have already been
automated using ansible. But I'm stuck in the last steps.

I'll describe how I'd go about it. This assumes you are running one play over all the hosts, and that there's a group called mysql_cluster. It also assumes that the first host in that group actually works.

Here are the remaining steps:

1. Use '/etc/init.d/mysql bootstrap-pxc' to bootstrap the cluster from
node1, keep the mysql instance on node2 shut.

- service: name=mysql state=stopped

- shell: /etc/init.d/mysql bootstrap-pxc
  # don't use play_hosts nor run_once here - they don't act like we want when used with serial
  when: inventory_hostname == groups.mysql_cluster[0]
  register: create_cluster

- name: Make sure no host continues if bootstrap failed
  assert: not (hostvars[groups.mysql_cluster [0]].create_cluster) | failed

2. Connect to mysql on node1 and create accounts for xtrabackup

See the shell task in 1. for a way to only act on node1

3. Use '/etc/init.d/mysql start' to start the mysql instance on node2
and
it will join the cluster automatically.

- service: name=mysql state=started
  # you can just run that everywhere, as mysql is already started on node1 anyway