Adoptable Cookbooks List

Looking for a cookbook to adopt? You can now see a list of cookbooks available for adoption!
List of Adoptable Cookbooks

Supermarket Belongs to the Community

Supermarket belongs to the community. While Chef has the responsibility to keep it running and be stewards of its functionality, what it does and how it works is driven by the community. The chef/supermarket repository will continue to be where development of the Supermarket application takes place. Come be part of shaping the direction of Supermarket by opening issues and pull requests or by joining us on the Chef Mailing List.

Select Badges

Select Supported Platforms

Select Status


mysql-mha (3) Versions 0.1.2

Installs/Configures MHA and MHA Helper

cookbook 'mysql-mha', '~> 0.1.2', :supermarket
cookbook 'mysql-mha', '~> 0.1.2'
knife supermarket install mysql-mha
knife supermarket download mysql-mha
Quality 17%

mysql-mha Cookbook

Join the chat at
Cookbook Version

Deploys MHA and MHA Helper to manage failover of MySQL replication clusters. MHA helper is a Python module that supplements in doing proper failover using MHA.



  • RHEL / CentOS version 6.x


  • Chef 11+


  • packagecloud
  • ssh
  • sudo
  • user
  • yum-epel
  • zap


On the manager node, which is the node which will manage the MySQL replication clusters, include the following recipe:

include_recipe "mysql-mha::manager"

On all the other MySQL nodes (master and slave), include the following recipe:

include_recipe "mysql-mha::node"

Use knife to create the required data bags.

$ knife data bag create mysql_mha_config
$ knife data bag create mysql_mha_secrets

The mysql_mha_config data bag contains the main configuration minus the sensitive items like user passwords.

Create cluster configuration in the data_bag/mysql_mha_config/ directory.

The latest version of knife supports reading data bags from a file and automatically looks in a directory called +data_bags+ in the current directory. The "bag" should be a directory with JSON files of each item.

  "id": "test_pod",
  "comment": "MHA replication pod 'test_pod' configuration",
  "mysql": {
    "user": "mha",
    "repl_user": "repl"
  "remote_user": {
    "id": "mha",
    "comment": "user used by MHA to login to managed nodes",
    "home": "/home/mha",
    "uid": "10011",
    "groups": ["mysql"],
    "ssh_keys": [
      "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAwHjA7iaA0/+TD0roAmyOqYFp3DMpuJ/Xee260gio5igLeV6DHyPBskHhcCOWFcZ+uCAOGIm+Yye9nxuspWFEWCa4L1SxniBEpRGtGyorbgz7Zmh/6VlcZOUBTe1GtaprokGAtzP2gaQbRpJ1c0oX3JZ4lVH6Oro3keCGyncZMFJ2nTu0hOgbJPA3XZkRwO0DhB/8IbPu6NwXVcDjaMfTmpj4kp722RFuEUgGrDBwx/vasakpcBMHF+a6QL0gAODHMttQB1kk1hCV4fQtiTSrbG97jldlcC7VvSqK79twpQNe9y06jnMah8xdvZ69mw/4k3Av+Vv3I4KHxvN9wE59Tw== root@manager-centos-66"
  "vip_type": "metal",
  "writer_vip_cidr": "",
  "report_email": "",
  "smtp_host": "localhost",
  "requires_sudo": "yes",
  "super_read_only": "no",
  "cluster_interface": "eth1"

For the above:

$ mkdir data_bags/mysql_mha_config
$ $EDITOR data_bags/mysql_mha_config/test_pod.json

Paste the user's public SSH key into the ssh_keys value. Also make sure the uid is unique.

Create cluster configuration in the data_bag/mysql_mha_secrets directory.

The mysql_mha_secrets data bag is an encrypted data bag that contains the secondary part of the configuration which includes the sensitive items like user passwords.

  "id": "test_pod",
  "comment": "MHA replication pod 'test_pod' secrets",
  "mysql": {
    "password": "mha",
    "repl_password": "repl"
  "remote_user": {
    "ssh_private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEogIBAAKCAQEAwHjA7iaA0/+TD0roAmyOqYFp3DMpuJ/Xee260gio5igLeV6D\nHyPBskHhcCOWFcZ+uCAOGIm+Yye9nxuspWFEWCa4L1SxniBEpRGtGyorbgz7Zmh/\n6VlcZOUBTe1GtaprokGAtzP2gaQbRpJ1c0oX3JZ4lVH6Oro3keCGyncZMFJ2nTu0\nhOgbJPA3XZkRwO0DhB/8IbPu6NwXVcDjaMfTmpj4kp722RFuEUgGrDBwx/vasakp\ncBMHF+a6QL0gAODHMttQB1kk1hCV4fQtiTSrbG97jldlcC7VvSqK79twpQNe9y06\njnMah8xdvZ69mw/4k3Av+Vv3I4KHxvN9wE59TwIBIwKCAQEAlHpo8jr1qtsZrLYg\nsWmv4djcoo3eWzl6Vr60sKeYPIV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pZRI2Ml5Ekzng+zXv27IY/1+7ukO6zlbtkZsdJcG/\n720B150vR1JXmYQlWLYNcgMVb/U/gfPeYI5hpxzl8DyGnSsEYJo7jr8wJ9hebqgf\nyNlZaURrwMLOm9DrnGih9qbWgtMMhHP2GHiQRqTpexhs20dm8U8=\n-----END RSA PRIVATE KEY-----"

For the above:

$ mkdir data_bags/mysql_mha_secrets
$ knife data bag create mysql_mha_config test_pod -z --secret-file /path/to/encrypted_data_bag_secret

The data bag name is the name of the cluster and the following attribute must be set on all the nodes that belong to the same MySQL replication cluster:
node['mysql_mha']['pod_name'] = 'test_pod'

Note how the attribute above matches the name of the data bag in the example above.

Every MySQL node that is the candidate master (including current active MySQL master and all the other nodes that can potentially become masters) must have the following attribute set:
node['mysql_mha']['node']['candidate_master'] = '1'

You can optionally prevent MHA from checking for replication delay on a node, if you want the node to always act as a master irrespective if its the most latest slave or not:
node['mysql_mha']['node']['check_repl_delay'] = '0'

If you do not want a MySQL node to every become a master, then you can set the following attribute:
node['mysql_mha']['node']['no_master'] = '1'

The following attributes must be setup for MHA to function correctly:
node['mysql_mha']['node']['mysql_port'] = '3306'
node['mysql_mha']['node']['mysql_binlog_dir'] = '/var/lib/mysql'
node['mysql_mha']['node']['ssh_port'] = '22'

Additionally following considerations must be taken into account:

  • The cookbook does not create the MySQL users you specify inside the configuration in the data bags. The must already exist.
  • The writer VIP (specified using the option 'writer_vip_cidr') must already be assigned when the recipe is run for the first time.

License & Authors

Author: Ovais Tariq (

Copyright: 2009-2015, Ovais Tariq
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.

Dependent cookbooks

packagecloud >= 0.0.0
ssh >= 0.0.0
sudo >= 2.7.1
user >= 0.0.0
yum-epel <= 0.6.0
zap >= 0.6.0

Contingent cookbooks

There are no cookbooks that are contingent upon this one.

mysql-mha Cookbook CHANGELOG


  • initial release

Collaborator Number Metric

0.1.2 failed this metric

Failure: Cookbook has 0 collaborators. A cookbook must have at least 2 collaborators to pass this metric.

Contributing File Metric

0.1.2 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of, and your repo must contain a file

Foodcritic Metric

0.1.2 failed this metric

FC064: Ensure issues_url is set in metadata: mysql-mha/metadata.rb:1
FC065: Ensure source_url is set in metadata: mysql-mha/metadata.rb:1
FC066: Ensure chef_version is set in metadata: mysql-mha/metadata.rb:1
FC069: Ensure standardized license defined in metadata: mysql-mha/metadata.rb:1
FC074: LWRP should use DSL to define resource's default action: mysql-mha/resources/sshkey.rb:1
Run with Foodcritic Version 16.3.0 with tags metadata,correctness ~FC031 ~FC045 and failure tags any

No Binaries Metric

0.1.2 passed this metric

Testing File Metric

0.1.2 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of, and your repo must contain a file

Version Tag Metric

0.1.2 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of, and your repo must include a tag that matches this cookbook version number