• This repository has been archived on 07/Apr/2018
  • Stars
    star
    186
  • Rank 207,316 (Top 5 %)
  • Language
    Ruby
  • License
    Apache License 2.0
  • Created over 12 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

DEPRECATED: Development repository for Chef database cookbook

Database Cookbook

Build Status Cookbook Version

The main highlight of this cookbook is the database and database_user resources for managing databases and database users in a RDBMS. Providers for MySQL, PostgreSQL and SQL Server are also provided, see usage documentation below.

DEPRECATION

This cookbook has been deprecated. The original intent was to abstract database implementation details away from the end user. In hindsight this was a mistake as it is difficult / impossible to make a generic interface for databases that works accross all systems. Instead we plan to move the individual providers into their respective cookbooks (mysql, postgresql, sqlite, sql_server) where they can fully utilize the feature set of the underlying DB systems.

Requirements

Platforms

  • Debian / Ubuntu derivatives
  • RHEL derivatives
  • Fedora

Chef

  • Chef 12.1+

Cookbooks

  • postgresql

Resources/Providers

These resources aim to expose an abstraction layer for interacting with different RDBMS in a general way. Currently the cookbook ships with providers for MySQL, PostgreSQL and SQL Server. Please see specific usage in the Example sections below. The providers use specific Ruby gems installed under Chef's Ruby environment to execute commands and carry out actions. These gems will need to be installed before the providers can operate correctly. Specific notes for each RDBS flavor:

  • MySQL: leverages the mysql2 gem, which can be installed with the mysql2_chef_gem resource prior to use (available on the Supermarket). You must depend on the mysql2_chef_gem cookbook, then use a mysql2_chef_gem resource to install it. The resource allows the user to select MySQL client library versions, as well as optionally select MariaDB libraries.

  • PostgreSQL: leverages the pg gem which is installed as part of the postgresql::ruby recipe. You must declare include_recipe "database::postgresql" to include this.

  • SQL Server: leverages the tiny_tds gem which is installed as part of the sql_server::client recipe.

  • SQLite: leverages the sqlite3 gem which is installed as part of the database::sqlite recipe. You must declare include_recipe "database::sqlite" to include this.

database

Manage databases in a RDBMS. Use the proper shortcut resource depending on your RDBMS: mysql_database, postgresql_database, sql_server_database or sqlite_database.

Actions

  • :create: create a named database
  • :drop: drop a named database
  • :query: execute an arbitrary query against a named database

Attribute Parameters

  • database_name: name attribute. Name of the database to interact with

  • connection: hash of connection info. valid keys include :host, :port, :username, and :password

  • sql: string of sql or a block that executes to a string of sql, which will be executed against the database. used by :query action only

  • The database cookbook uses the mysql2 gem.

"The value of host may be either a host name or an IP address. If host is NULL or the string "127.0.0.1", a connection to the local host is assumed. For Windows, the client connects using a shared-memory connection, if the server has shared-memory connections enabled. Otherwise, TCP/IP is used. For a host value of "." on Windows, the client connects using a named pipe, if the server has named-pipe connections enabled. If named-pipe connections are not enabled, an error occurs."

If you specify a :socket key and are using the mysql_service resource to set up the MySQL service, you'll need to specify the path in the form /var/run/mysql-<instance name>/mysqld.sock.

Providers

  • Chef::Provider::Database::Mysql: shortcut resource mysql_database
  • Chef::Provider::Database::Postgresql: shortcut resource postgresql_database
  • Chef::Provider::Database::SqlServer: shortcut resource sql_server_database
  • Chef::Provider::Database::Sqlite: shortcut resource sqlite_database

Examples

# Create a mysql database
mysql_database 'wordpress-cust01' do
  connection(
    :host     => '127.0.0.1',
    :username => 'root',
    :password => node['wordpress-cust01']['mysql']['initial_root_password']
  )
  action :create
end
# Create a mysql database on a named mysql instance
mysql_database 'oracle_rools' do
  connection(
    :host     => '127.0.0.1',
    :username => 'root',
    :socket   => "/var/run/mysql-#{instance-name}/mysqld.sock"
    :password => node['mysql']['server_root_password']
  )
  action :create
end
# Create a sql server database
sql_server_database 'mr_softie' do
  connection(
    :host     => '127.0.0.1',
    :port     => node['sql_server']['port'],
    :username => 'sa',
    :password => node['sql_server']['server_sa_password'],
    :options  => { 'ANSI_NULLS' => 'ON', 'QUOTED_IDENTIFIER' => 'OFF' }
  )
  action :create
end
# create a postgresql database
postgresql_database 'mr_softie' do
  connection(
    :host      => '127.0.0.1',
    :port      => 5432,
    :username  => 'postgres',
    :password  => node['postgresql']['password']['postgres']
  )
  action :create
end
# create a postgresql database with additional parameters
postgresql_database 'mr_softie' do
  connection(
    :host     => '127.0.0.1',
    :port     => 5432,
    :username => 'postgres',
    :password => node['postgresql']['password']['postgres']
  )
  template 'DEFAULT'
  encoding 'DEFAULT'
  tablespace 'DEFAULT'
  connection_limit '-1'
  owner 'postgres'
  action :create
end
# Externalize conection info in a ruby hash
mysql_connection_info = {
  :host     => '127.0.0.1',
  :username => 'root',
  :password => node['mysql']['server_root_password']
}

sql_server_connection_info = {
  :host     => '127.0.0.1',
  :port     => node['sql_server']['port'],
  :username => 'sa',
  :password => node['sql_server']['server_sa_password']
}

postgresql_connection_info = {
  :host     => '127.0.0.1',
  :port     => node['postgresql']['config']['port'],
  :username => 'postgres',
  :password => node['postgresql']['password']['postgres']
}

# Same create commands, connection info as an external hash
mysql_database 'foo' do
  connection mysql_connection_info
  action :create
end

sql_server_database 'foo' do
  connection sql_server_connection_info
  action     :create
end

postgresql_database 'foo' do
  connection postgresql_connection_info
  action     :create
end

# Create database, set provider in resource parameter
database 'bar' do
  connection mysql_connection_info
  provider   Chef::Provider::Database::Mysql
  action     :create
end

database 'bar' do
  connection sql_server_connection_info
  provider   Chef::Provider::Database::SqlServer
  action     :create
end

database 'bar' do
  connection postgresql_connection_info
  provider   Chef::Provider::Database::Postgresql
  action     :create
end



# Drop a database
mysql_database 'baz' do
  connection mysql_connection_info
  action    :drop
end



# Query a database
mysql_database 'flush the privileges' do
  connection mysql_connection_info
  sql        'flush privileges'
  action     :query
end


# Query a database from a sql script on disk
mysql_database 'run script' do
  connection mysql_connection_info
  sql { ::File.open('/path/to/sql_script.sql').read }
  action :query
end



# Vacuum a postgres database
postgresql_database 'vacuum databases' do
  connection      postgresql_connection_info
  database_name 'template1'
  sql 'VACUUM FULL VERBOSE ANALYZE'
  action :query
end
# Create, Insert, Query a SQLite database
# Note that inserting anything in to the database will create it automaticly.
sqlite_database 'mr_softie' do
  database_name '/path/to/database.db3'
  sql "sql command"
  action :query
end

# Delete the database, will remove the file
sqlite_database 'mr_softie' do
  database_name '/path/to/database.db3'
  action :drop
end

database_user

Manage users and user privileges in a RDBMS. Use the proper shortcut resource depending on your RDBMS: mysql_database_user, postgresql_database_user, or sql_server_database_user.

Actions

  • :create: create a user
  • :drop: drop a user
  • :grant: manipulate user privileges on database objects

Attribute Parameters

  • username: name attribute. Name of the database user
  • password: password for the user account
  • database_name: Name of the database to interact with
  • connection: hash of connection info. valid keys include :host, :port, :username, :password
  • privileges: array of database privileges to grant user. used by the :grant action. default is :all
  • host: host where user connections are allowed from. used by MySQL provider only. default is '127.0.0.1'
  • table: table to grant privileges on. used by :grant action and MySQL provider only. default is '*' (all tables)
  • require_ssl: true or false to force SSL connections to be used for user
  • require_x509: true or false to force SSL with client certificate verification

Providers

  • Chef::Provider::Database::MysqlUser: shortcut resource mysql_database_user
  • Chef::Provider::Database::PostgresqlUser: shortcut resource postgresql_database_user
  • Chef::Provider::Database::SqlServerUser: shortcut resourcesql_server_database_user

Examples

# create connection info as an external ruby hash
mysql_connection_info = {
  :host     => '127.0.0.1',
  :username => 'root',
  :password => node['mysql']['server_root_password']
}

postgresql_connection_info = {
  :host     => '127.0.0.1',
  :port     => node['postgresql']['config']['port'],
  :username => 'postgres',
  :password => node['postgresql']['password']['postgres']
}

sql_server_connection_info = {
  :host     => '127.0.0.1',
  :port     => node['sql_server']['port'],
  :username => 'sa',
  :password => node['sql_server']['server_sa_password']
}

# Create a mysql user but grant no privileges
mysql_database_user 'disenfranchised' do
  connection mysql_connection_info
  password   'super_secret'
  action     :create
end

# Do the same but pass the provider to the database resource
database_user 'disenfranchised' do
  connection mysql_connection_info
  password   'super_secret'
  provider   Chef::Provider::Database::MysqlUser
  action     :create
end

# Create a postgresql user but grant no privileges
postgresql_database_user 'disenfranchised' do
  connection postgresql_connection_info
  password   'super_secret'
  action     :create
end

# The same as above but utilizing hashed password string instead of
# plain text one
postgresql_database_user 'disenfranchised' do
  connection    postgresql_connection_info
  password      hashed_password('md5eacdbf8d9847a76978bd515fae200a2a')
  action        :grant
end

# Do the same but pass the provider to the database resource
database_user 'disenfranchised' do
  connection postgresql_connection_info
  password   'super_secret'
  provider   Chef::Provider::Database::PostgresqlUser
  action     :create
end

# Create a sql server user but grant no privileges
sql_server_database_user 'disenfranchised' do
  connection sql_server_connection_info
  password   'super_secret'
  action     :create
end

# Drop a mysql user
mysql_database_user 'foo_user' do
  connection mysql_connection_info
  action     :drop
end

# Bulk drop sql server users
%w(disenfranchised foo_user).each do |user|
  sql_server_database_user user do
    connection sql_server_connection_info
    action     :drop
  end
end

# Grant SELECT, UPDATE, and INSERT privileges to all tables in foo db from all hosts
mysql_database_user 'foo_user' do
  connection    mysql_connection_info
  password      'super_secret'
  database_name 'foo'
  host          '%'
  privileges    [:select,:update,:insert]
  action        :grant
end

# The same as above but utilizing hashed password string instead of
# plain text one
mysql_database_user 'foo_user' do
  connection    mysql_connection_info
  password      hashed_password('*664E8D709A6EBADFC68361EBE82CF77F10211E52')
  database_name 'foo'
  host          '%'
  privileges    [:select,:update,:insert]
  action        :grant
end

# Grant all privileges on all databases/tables from 127.0.0.1
mysql_database_user 'super_user' do
  connection mysql_connection_info
  password   'super_secret'
  action     :grant
end

# grant all privileges on all tables, sequences and functions in public schema of foo db
postgresql_database_user 'foo_user' do
  connection    postgresql_connection_info
  database_name 'foo'
  schema_name 'public'
  tables [:all]
  sequences [:all]
  functions [:all]
  privileges    [:all]
  action        [:grant, :grant_schema, :grant_table, :grant_sequence, :grant_function]
end

# grant select,update,insert privileges to all tables in foo db
sql_server_database_user 'foo_user' do
  connection    sql_server_connection_info
  password      'super_secret'
  database_name 'foo'
  privileges    [:select,:update,:insert]
  action        :grant
end

License & Authors

Author: Cookbook Engineering Team ([email protected])

Copyright: 2009-2016, Chef Software, Inc.

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

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

cookbooks

DEPRECATED: This repository has been split up into separate repositories by cookbook under the "opscode-cookbooks" organization.
1,495
star
2

chef-repo

DEPRECATED: Use of this repository is deprecated. We recommend using the chef generate repo command that comes with ChefDK.
859
star
3

vagrant-omnibus

A Vagrant plugin that ensures the desired version of Chef is installed via the platform-specific Omnibus packages.
Ruby
551
star
4

devops-kungfu

Chef Style DevOps Kung fu
JavaScript
528
star
5

chef-provisioning

A library for creating machines and infrastructures idempotently in Chef.
Ruby
524
star
6

chef-dk

DEPRECATED: A streamlined development and deployment workflow for Chef Infra platform.
Ruby
384
star
7

windows

Development repository for Chef Cookbook windows
Ruby
252
star
8

chef-fundamentals

DEPRECATED: Chef Fundamentals training materials
CSS
205
star
9

chef-client

Development repository for Chef Client cookbook
Ruby
175
star
10

stove

DEPRECATED: A utility for packaging and releasing Chef cookbooks
Ruby
168
star
11

minitest-chef-handler

Run minitest suites after your Chef recipes to check the status of your system.
Ruby
164
star
12

knife-rackspace

Chef knife plug-in for Rackspace
Ruby
153
star
13

chef-rfc

Public RFCs for Chef and related projects
Ruby
148
star
14

chef-provisioning-aws

AWS driver and resources for Chef that uses the AWS SDK
Ruby
142
star
15

sudo

Development repository for sudo cookbook
Ruby
117
star
16

build-essential

Development repository for build-essential Chef Cookbook
Ruby
116
star
17

chef-api

DEPRECATED: A tiny Chef API client with minimal dependencies
Ruby
107
star
18

chef-provisioning-docker

Docker provisioner for chef-provisioning
Ruby
93
star
19

erchef

DEPRECATED: Erlang based Chef Server top-level OTP release project
Erlang
89
star
20

knife-acl

knife plugin for working with ACLs on Chef Server
Ruby
81
star
21

delivery-cli

The command line tool for the workflow capabilities in Chef Automate.
Rust
80
star
22

knife-linode

DEPRECATED: Chef knife plug-in for Linode
Ruby
78
star
23

omnibus-chef

Omnibus packaging for Chef
77
star
24

chef-web-docs-2016

DEPRECATED - All The Documentation
HTML
75
star
25

omnibus_updater

DEPRECATED: Chef cookbook to update the omnibus packaged Chef client
Ruby
74
star
26

openssl

Development repository for openssl cookbook
Ruby
74
star
27

terraform-provisioner-inspec

Terraform InSpec Provisioner Plugin
Go
68
star
28

rails-quick-start

DEPRECATED: Repository used with the Chef Rails Quick Start Guide
HTML
63
star
29

ubuntu

Development repository for Chef Cookbook ubuntu
Ruby
61
star
30

chef-vault

chef-vault cookbook
Ruby
61
star
31

route53

DEPRECATED: Provides resources for adding and removing records from Amazon Route53
Ruby
60
star
32

knife-container

DEPRECATED: Container support for Chef's Knife Command
Ruby
57
star
33

audit

Audit Cookbook for Chef Compliance
Ruby
57
star
34

chef-provisioning-fog

Fog driver for Chef Provisioning
Ruby
54
star
35

chef_nginx

Chef Software support NGINX cookbook
Ruby
53
star
36

quick-reference

quick reference documentation
52
star
37

ohai

Development repository for Chef Cookbook ohai
Ruby
49
star
38

chef_handler

DEPRECATED: Development repository for Chef Cookbook chef_handler
Ruby
49
star
39

dmg

Development repository for dmg Chef cookbook
Ruby
45
star
40

omnibus-chef-server

Deprecated: Omnibus packaging for Opscode Chef Server (OSC 11.x only).
Ruby
44
star
41

inspec-aws-old

[Deprecated] This is integrated in InSpec 2.0 now
Ruby
42
star
42

django-quick-start

DEPRECATED: Django Quick Start Guide Chef Repository
40
star
43

hubot

DEPRECATED: Chef cookbook for deploying and managing an instance of Github's Hubot.
Ruby
40
star
44

httpd

DEPRECATED: Library cookbook with Apache httpd primitives
Ruby
39
star
45

aws_native_chef_server

Cloudformation templates for building a scalable cloud-native Chef Server on AWS
Shell
37
star
46

delivery-truck

DEPRECATED: Delivery build cb for pipelines
Ruby
36
star
47

bluepill

Development repository for bluepill Chef Cookbook
Ruby
35
star
48

unicorn

DEPRECATED: Development repository for Chef Cookbook unicorn
Ruby
34
star
49

chef-server-cluster

DEPRECATED: Chef Cookbook to manage Chef Clusters
Ruby
33
star
50

opscode-packages

Packages of Opscode Software for various platforms
Ruby
33
star
51

openstack-chef-repo

DEPRECATED: Chef Repository for OpenStack
Ruby
32
star
52

cookbook-guide

Chef Technical Alliances guide for writing quality cookbooks
Ruby
31
star
53

tar

Deprecated: Chef cookbook for tar packages
Ruby
31
star
54

audit-cis

DEPRECATED: Recipes to perform chef audit mode check for CIS Benchmarks
Ruby
31
star
55

omnibus

Prepares a machine to be an Omnibus builder. โ”ฌโ”€โ”€โ”ฌโ—ก๏พ‰(ยฐ -ยฐ๏พ‰)
Ruby
28
star
56

libarchive

Deprecated: A library cookbook for manipulating archive files
Ruby
28
star
57

resource

DEPRECATED: Easier, More Powerful Chef Resources
27
star
58

chef-sugar

Ruby
27
star
59

ruby

DEPRECATED: Chef Cookbook for Managing Ruby from Packages
Ruby
27
star
60

locale

Chef cookbook to configure the system locale on Linux systems
Ruby
26
star
61

chef-server-webui

DEPRECATED: Web Interface to Open Source Chef Server 11
JavaScript
24
star
62

private-chef-administration

DEPRECATED: Private Chef Administration Guide
Python
24
star
63

bookshelf

DEPRECATED: Minimal S3 Clone
Erlang
24
star
64

opscode-agent

Opscode Agent, providing RESTful and AMQP access to Chef and Ohai
Ruby
23
star
65

pantry-chef-repo

A Chef Repository For Pantry
Shell
22
star
66

habitat

Chef Cookbook for Habitat
Ruby
22
star
67

chef-provisioning-vagrant

Vagrant provisioner for chef-provisioning
Ruby
22
star
68

microsoft_azure

Windows Azure Cookbook for Chef
Ruby
21
star
69

chef-init

PID1 for your Chef containers
Ruby
21
star
70

knife-opc

Knife plugin for managing Chef Server Organizations
Ruby
21
star
71

zsh

DEPRECATED: Development repository for Chef Cookbook zsh
Ruby
21
star
72

push-jobs-cookbook

Development repository for Chef Cookbook push-jobs
Ruby
21
star
73

chef-provisioning-azure

DEPRECATED: Azure driver for chef-provisioning!
Ruby
21
star
74

delivery-cluster

DEPRECATED: Deployment cookbook for standing up Delivery clusters using chef-provisioning.
Ruby
20
star
75

gunicorn

DEPRECATED: Development repository for Chef Cookbook gunicorn
Ruby
20
star
76

dsc

DEPRECATED: Preview of PowerShell Desired State Configuration (DSC) integration with the Chef DSL
Ruby
19
star
77

cis-el7-l1-hardening

Hardening cookbook for CIS Level 1 for RHEL 7 based operating systems
Ruby
19
star
78

logwatch

Development repository for Chef Cookbook logwatch
Ruby
19
star
79

ec-metal

Chef Provisioning-based tool for creating, managing and testing Enterprise Chef HA clusters
Ruby
19
star
80

inspec-vmware

InSpec VMware Resource Pack (Incubation)
Ruby
19
star
81

whitelist-node-attrs

Look here:
Ruby
18
star
82

java-quick-start

DEPRECATED: Chef Java Quick Start Guide
18
star
83

community-summits

Wikis to capture notes for Community Summits
18
star
84

whitelist-node-attrs-cookbook

DEPRECATED: Development repository for whitelist-node-attrs cookbook
Ruby
18
star
85

activemq

Development repository for activemq Chef Cookbook
Ruby
18
star
86

chef-server-cloudformation-templates

Collection of AWS Cloudformation templates for installing Chef Server 12 on EC2
17
star
87

php-quick-start

DEPRECATED: PHP quickstart guide for Chef
17
star
88

knife-eucalyptus

Chef knife plug-in for Eucalyptus
Ruby
16
star
89

lambda_ebs_snapshot

Terraform config for automatic EBS snapshots
HCL
16
star
90

knife-push

knife commands for Chef Push Jobs
Ruby
16
star
91

opscode-pushy-server

Chef Push Jobs Server
Erlang
16
star
92

chef-provisioning-ssh

Provision Machines Via SSH or WinRM Using Chef Provisioning
Ruby
15
star
93

automeck

Streamlines setting up and using meck-based mocks
Erlang
15
star
94

compat_resource

Cookbook to bring some features from future Chef to earlier versions
Ruby
15
star
95

chef-container

Official build definitions for Chef's Docker images
Ruby
14
star
96

chef_wm

DEPRECATED repository. Now lives in chef-server.
Erlang
14
star
97

opscode-omnibus

Deprecated: Omnibus packaging for Chef Server - Use Chef Server Instead
Ruby
14
star
98

win32-sound

A Ruby library for playing and controlling sounds on MS Windows.
Ruby
13
star
99

chef-pedant

DEPRECATED Integration Test Suite for Chef Sever - replaced with oc-chef-pedant
Ruby
13
star
100

chef-server-solo-install

Bootstrap a Chef Server via Chef Solo
Ruby
13
star