1. Home
  2. Docs
  3. ClusterControl
  4. Installation
  5. Automatic Installation
  6. Ansible Role

Ansible Role

If you are automating your infrastructure using Ansible, we have created a role for this purpose and it is available at Ansible Galaxy. This role also supports deploy a new cluster and import an existing cluster into ClusterControl automatically, as shown under Example Playbook.

Getting the role is as easy as:

$ ansible-galaxy install severalnines.clustercontrol

Usage

1. Get the ClusterControl Ansible role from Ansible Galaxy or Github.

Ansible GalaxyGithub
$ ansible-galaxy install severalnines.clustercontrol
$ git clone https://github.com/severalnines/ansible-clustercontrol
$ cp -rf ansible-clustercontrol /etc/ansible/roles/severalnines.clustercontrol

2. Create a playbook. See Example Playbook section.

3. Run the playbook.

$ ansible-playbook cc.playbook

4. Once ClusterControl is installed, go to http://ClusterControl_host/clustercontrol and create the default admin user/password.

5. On ClusterControl node, setup passwordless SSH key to all target DB nodes. For example, if ClusterControl node is 192.168.0.10 and DB nodes are 192.168.0.11, 192.168.0.12 and 192.168.0.13:

$ ssh-copy-id 192.168.0.11 # DB1
$ ssh-copy-id 192.168.0.12 # DB2
$ ssh-copy-id 192.168.0.13 # DB3
Note

Enter the password to complete the passwordless SSH setup.

6. Start to deploy a new database cluster or add an existing one.

Example Playbook

The simplest playbook would be:

- hosts: clustercontrol-server
  roles:
    - { role: severalnines.clustercontrol }

If you would like to specify custom configuration values as explained above, create a file called vars/main.yml and include it inside the playbook:

- hosts: 192.168.10.15
  vars:
    - vars/main.yml
  roles:
    - { role: severalnines.clustercontrol, tags: controller }

Inside vars/main.yml:

controller: true
mysql_root_username: admin
mysql_root_password: super-user-password
cmon_mysql_password: super-cmon-password
cmon_mysql_port: 3307

If you are running as another user, ensure the user has the ability to escalate as a superuser via sudo. Example playbook for Ubuntu 12.04 with sudo password enabled:

- hosts: [email protected]
  become: yes
  become_user: root
  roles:
    - { role: severalnines.clustercontrol, tags: controller }

Then, execute the command with the --ask-become-pass flag, for example:

$ ansible-playbook cc.playbook --ask-become-pass

Install ClusterControl with automatic deployment

The role also supports automatic database deployment by leveraging the CMON RPC interface. This will minimize the deployment time to get your database cluster up and running. An example playbook for automatic deployment in AWS EC2 can be found here.

Consider the following inside /etc/ansible/hosts:

[clustercontrol]
192.168.55.100

[galera]
192.168.55.171
192.168.55.172
192.168.55.173

[mysql-replication]
192.168.55.204
192.168.55.205

The following playbook will install ClusterControl on 192.168.55.100, set up passwordless SSH on Galera and MySQL replication nodes, then post a create or add job into ClusterControl for the deployment:

- hosts: clustercontrol
  roles:
    - { role: severalnines.clustercontrol, tags: controller }
 
- hosts:
    - mysql-replication
    - galera
  roles:
    - { role: severalnines.clustercontrol, tags: dbnodes }
  vars:
    clustercontrol_ip_address: 192.168.55.100
    ssh_user: root
 
- hosts: clustercontrol
  roles:
    - { role: severalnines.clustercontrol, tags: deploy-database }
  vars:
    cc_cluster:
      # create new mysql replication. first node is the master
      - deployment: true
        operation: "create"
        cluster_type: "replication"
        mysql_hostnames:
          - '192.168.55.204'
          - '192.168.55.205'
        mysql_cnf_template: "my.cnf.repl57"
        mysql_datadir: "/var/lib/mysql"
        mysql_password: "password"
        mysql_port: 3306
        mysql_version: "5.7"
        ssh_keyfile: "/root/.ssh/id_rsa"
        ssh_port: "22"
        ssh_user: "root"
        sudo_password: ""
        type: "mysql"
        vendor: "oracle"
    # add existing galera.
      - deployment: true
        operation: "add"
        cluster_type: "galera"
        mysql_password: "password"
        mysql_hostnames:
          - '192.168.55.171'
          - '192.168.55.172'
          - '192.168.55.173'
        ssh_keyfile: "/root/.ssh/id_rsa"
        ssh_port: 22
        ssh_user: root
        vendor: percona
        sudo_password: ""
        galera_version: "3.x"
        enable_node_autorecovery: true
        enable_cluster_autorecovery: true
    # minimal create new galera
      - deployment: true
        operation: "create"
        cluster_type: "galera"
        mysql_cnf_template: "my.cnf.galera"
        mysql_datadir: "/var/lib/mysql"
        mysql_hostnames:
          - '192.168.55.191'
          - '192.168.55.192'
          - '192.168.55.193'
        mysql_password: "password"
        mysql_port: 3306
        mysql_version: "5.6"
        ssh_keyfile: "/root/.ssh/id_rsa"
        ssh_user: "root"
        sudo_password: ""
        vendor: "percona"

Take note of the following tags in the role lines:

  • no tag (default) – Install ClusterControl
  • dbnodes – For all managed nodes to setup passwordless SSH
  • deploy-database – To deploy database after ClusterControl is installed

Variables are mostly similar to keys in the JSON job command created in ClusterControl’s Cluster Job. If a key/value is not specified, the default value is used. For more details, check out the ClusterControl Ansible Github page.

Was this article helpful to you? Yes No