Skip to content

Instantly share code, notes, and snippets.

@lamont-granquist
Last active January 11, 2020 22:56
Show Gist options
  • Save lamont-granquist/96363534d31910ef1899 to your computer and use it in GitHub Desktop.
Save lamont-granquist/96363534d31910ef1899 to your computer and use it in GitHub Desktop.

Create a cookbook

$ mkdir /tmp/my_mysql
$ cd /tmp/my_mysql
$ chef generate cookbook .

Add Dependent Cookbooks

Make it depend on the mysql cookbook and the apt cookbook (for Ubuntu/RHEL) and yum cookbook (for CentOS)

Add the depends lines to the metadata.rb to pull in the cookbooks:

name             'my_mysql'
maintainer       ''
maintainer_email ''
license          ''
description      'Installs/Configures my_mysql'
long_description 'Installs/Configures my_mysql'
version          '0.1.0'

depends "mysql"
depends "apt"
depends "yum"

add include_recipe statements to run the "apt" "yum" and "mysql::server"` recipes so it knows which of the recipes from the dependent cookbooks to run:

#
# Cookbook Name:: my_mysql
# Recipe:: default
#
# Copyright (C) 2014
#
#
#

include_recipe "apt" if node["platform_family"] == "debian"
include_recipe "yum" if node["platform_family"] == "rhel"
include_recipe "mysql::server"

Fix .kitchen.yml for ChefDK 0.1.0 bug

in .kitchen.yml edit to replace the run list changing recipe[bar::default] to recipe[my_mysql::default]

suites:
  - name: default
    run_list:
      - recipe[my_mysql::default]
    attributes:

Test Convergence With Test Kitchen

$ cd /tmp/my_mysql
$ kitchen converge default-ubuntu-1204

Download cookbooks to your local ~/.berkshelf

$ cd /tmp/my_mysql
$ berks install

Upload cookbooks to your chef server

$ cd /tmp/my_mysql
$ berks upload

^^^ oops, this'll blow up because I wrote this using /tmp and you'll need to have ~/.chef/knife.rb configured to talk to your chef server, and you'll need to have the cookbook under your home directory somewhere (in your chef-repo).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment