Configuring Machines Using Chef (Solo)

Now that we have a two server instances for web and database, we need to get some software installed, like Apache and MySQL. To do that, we’re going to use OpsCode Chef. There are other tools out there that do the same kinds of things, like Puppet. Chef is what I’m the most familiar with and what I work with on a daily basis and it has an crazy amount of documentation to go along with it.

We will need to configure knife, the Chef command line tool to manage cookbooks, roles and other pieces of data used to install and configure software on the servers. Once knife is configured, we’ll start to import cookbooks from the internet (GitHub) and get them to run automatically when vagrant creates and boots a new machine instance.

For now, we’re going to use Chef Solo. Chef Solo is a version of Chef that loads all of it’s configuration data from the local file system. Since we’re configuring local vagrant machines, this is perfect first step. Later, we will migrate our local configuration up to OpsCode (Hosted Chef), and use Chef [Client] to load configuraiton data from the OpsCode servers. It is also possible to host your own Chef Server. We will not be covering that in this guide [right now].

Just like other parts of this guide, I present the minimal steps needed to get working servers in place. The vendors documentation will cover things is much more detail than I ever could here.

See also Chef Documentation

  1. Installing Chef
  2. Configuring Knife
  3. Import Cookbooks from GitHub
  4. Create Web/Database Roles
  5. Configure Chef Solo in Vagrantfile
  6. Provision the Instances
  7. Commit Our Work

Install Chef

To install Chef and its associate tools, we just need to add more gems to our Gemfile and use bundle install to download/install things for us. Open up Gemfile in your favorite editor and add the following lines to the bottom:

1 gem 'chef'
2 gem 'knife-github-cookbooks'

From the top: The first line installs Chef, the knive command line tool, and all the things chef needs to run locally. knife-github-cookbooks is a knife plugin that allows us up install recipes from GitHub and track them in our project repository.

Now, run bundle install:

 1 $ bundle install
 2 Fetching gem metadata from http://rubygems.org/......
 3 Using rake (0.9.2.2) 
 4 Using Platform (0.4.0) 
 5 Using archive-tar-minitar (0.5.2) 
 6 Using builder (3.1.3) 
 7 Installing bunny (0.8.0) 
 8 Using erubis (2.7.0) 
 9 Using highline (1.6.15) 
10 Using json (1.5.4) 
11 Installing mixlib-log (1.4.1) 
12 Installing mixlib-authentication (1.3.0) 
13 Installing mixlib-cli (1.2.2) 
14 Installing mixlib-config (1.1.2) 
15 Installing mixlib-shellout (1.0.0) 
16 Installing moneta (0.6.0) 
17 Using net-ssh (2.2.2) 
18 Installing net-ssh-gateway (1.1.0) 
19 Installing net-ssh-multi (1.1) 
20 Installing ipaddress (0.8.0) 
21 Installing systemu (2.5.2) 
22 Installing yajl-ruby (1.1.0) with native extensions 
23 Installing ohai (6.14.0) 
24 Installing mime-types (1.19) 
25 Installing rest-client (1.6.7) 
26 Installing polyglot (0.3.3) 
27 Installing treetop (1.4.10) 
28 Installing uuidtools (2.1.3) 
29 Installing chef (0.10.10) 
30 Using ffi (1.0.11) 
31 Using childprocess (0.3.5) 
32 Installing configuration (1.3.2) 
33 Using diff-lcs (1.1.3) 
34 Using gherkin (2.11.2) 
35 Using cucumber (1.2.1) 
36 Using i18n (0.6.1) 
37 Installing launchy (0.4.0) 
38 Installing knife-github-cookbooks (0.1.6) 
39 Using log4r (1.1.10) 
40 Using net-scp (1.0.4) 
41 Using open4 (1.3.0) 
42 Using popen4 (0.1.2) 
43 Using progressbar (0.11.0) 
44 Using rspec-core (2.11.1) 
45 Using rspec-expectations (2.11.3) 
46 Using rspec-mocks (2.11.3) 
47 Using rspec (2.11.0) 
48 Using thor (0.14.6) 
49 Using vagrant (1.0.5) 
50 Using virtualbox (0.9.2) 
51 Using veewee (0.2.3) 
52 Using bundler (1.1.5) 
53 Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

Configuring Knife

Before we use knife to manage our configuration, we need to tweak its settings file to let it know where we want to store cookbooks, roles, etc. Later in the guide, this file will also tell knife how to talk to the OpsCode servers and what authentication information to use when creating new machins in the cloud.

First, let’s take a look at the directory structure we created earlier in this guide:

 1 .
 2 ├── .chef
 3 ├── boxes
 4 ├── chef
 5 │   ├── cookbooks
 6 │   ├── data_bags
 7 │   ├── environments
 8 │   └── roles
 9 ├── definitions
10 ├── instances
11 └── iso

From the top: The .chef directory will contain the configuration and credentials it use knife, the command line interface for Chef/OpsCode. The chef directory will contain local copies of our cookbooks, data bags, environments, and roles.

In your favorite editor, create a a new file in .chef called knife.rb and add this to it:

1 current_dir = File.dirname(__FILE__)                                                                                                         
2 chef_dir    = File.expand_path("#{current_dir}/../chef")
3 cookbook_path ["#{chef_dir}/cookbooks"]

From the top: The first two lines just set where to find the main chef configuration directory relative to knife.rb, and the last line tells knife where to store it’s cookbooks.

Before we go any further, let’s just run knife without any options to see what options are available:

  1 $ knife
  2 ERROR: You need to pass a sub-command (e.g., knife SUB-COMMAND)
  3 
  4 Usage: knife sub-command (options)
  5     -s, --server-url URL             Chef Server URL
  6     -k, --key KEY                    API Client Key
  7         --[no-]color                 Use colored output, defaults to enabled
  8     -c, --config CONFIG              The configuration file to use
  9         --defaults                   Accept default values for all questions
 10     -d, --disable-editing            Do not open EDITOR, just accept the data as is
 11     -e, --editor EDITOR              Set the editor to use for interactive commands
 12     -E, --environment ENVIRONMENT    Set the Chef environment
 13     -F, --format FORMAT              Which format to use for output
 14     -u, --user USER                  API Client Username
 15         --print-after                Show the data after a destructive operation
 16     -V, --verbose                    More verbose output. Use twice for max verbosity
 17     -v, --version                    Show chef version
 18     -y, --yes                        Say yes to all prompts for confirmation
 19     -h, --help                       Show this message
 20 
 21 Available subcommands: (for details, knife SUB-COMMAND --help)
 22 
 23 ** BOOTSTRAP COMMANDS **
 24 knife bootstrap FQDN (options)
 25 
 26 ** CLIENT COMMANDS **
 27 knife client bulk delete REGEX (options)
 28 knife client create CLIENT (options)
 29 knife client delete CLIENT (options)
 30 knife client edit CLIENT (options)
 31 knife client list (options)
 32 knife client reregister CLIENT (options)
 33 knife client show CLIENT (options)
 34 
 35 ** CONFIGURE COMMANDS **
 36 knife configure (options)
 37 knife configure client DIRECTORY
 38 
 39 ** COOKBOOK COMMANDS **
 40 knife cookbook bulk delete REGEX (options)
 41 knife cookbook create COOKBOOK (options)
 42 knife cookbook delete COOKBOOK VERSION (options)
 43 knife cookbook download COOKBOOK [VERSION] (options)
 44 knife cookbook list (options)
 45 knife cookbook metadata COOKBOOK (options)
 46 knife cookbook metadata from FILE (options)
 47 knife cookbook show COOKBOOK [VERSION] [PART] [FILENAME] (options)
 48 knife cookbook test [COOKBOOKS...] (options)
 49 knife cookbook upload [COOKBOOKS...] (options)
 50 knife cookbook github compare COOKBOOK [USER/BRANCH] (options)
 51 knife cookbook github install USER/REPO [USER/REPO/BRANCH] (options)
 52 
 53 ** COOKBOOK SITE COMMANDS **
 54 knife cookbook site download COOKBOOK [VERSION] (options)
 55 knife cookbook site install COOKBOOK [VERSION] (options)
 56 knife cookbook site list (options)
 57 knife cookbook site search QUERY (options)
 58 knife cookbook site share COOKBOOK CATEGORY (options)
 59 knife cookbook site show COOKBOOK [VERSION] (options)
 60 knife cookbook site unshare COOKBOOK
 61 
 62 ** DATA BAG COMMANDS **
 63 knife data bag create BAG [ITEM] (options)
 64 knife data bag delete BAG [ITEM] (options)
 65 knife data bag edit BAG ITEM (options)
 66 knife data bag from file BAG FILE|FOLDER [FILE|FOLDER..] (options)
 67 knife data bag list (options)
 68 knife data bag show BAG [ITEM] (options)
 69 
 70 ** ENVIRONMENT COMMANDS **
 71 knife environment create ENVIRONMENT (options)
 72 knife environment delete ENVIRONMENT (options)
 73 knife environment edit ENVIRONMENT (options)
 74 knife environment from file FILE (options)
 75 knife environment list (options)
 76 knife environment show ENVIRONMENT (options)
 77 
 78 ** EXEC COMMANDS **
 79 knife exec [SCRIPT] (options)
 80 
 81 ** HELP COMMANDS **
 82 knife help [list|TOPIC]
 83 
 84 ** INDEX COMMANDS **
 85 knife index rebuild (options)
 86 
 87 ** NODE COMMANDS **
 88 knife node bulk delete REGEX (options)
 89 knife node create NODE (options)
 90 knife node delete NODE (options)
 91 knife node edit NODE (options)
 92 knife node from file FILE (options)
 93 knife node list (options)
 94 knife node run_list add [NODE] [ENTRY[,ENTRY]] (options)
 95 knife node run_list remove [NODE] [ENTRIES] (options)
 96 knife node show NODE (options)
 97 
 98 ** RECIPE COMMANDS **
 99 knife recipe list [PATTERN]
100 
101 ** ROLE COMMANDS **
102 knife role bulk delete REGEX (options)
103 knife role create ROLE (options)
104 knife role delete ROLE (options)
105 knife role edit ROLE (options)
106 knife role from file FILE [FILE..] (options)
107 knife role list (options)
108 knife role show ROLE (options)
109 
110 ** SEARCH COMMANDS **
111 knife search INDEX QUERY (options)
112 
113 ** SSH COMMANDS **
114 knife ssh QUERY COMMAND (options)
115 
116 ** STATUS COMMANDS **
117 knife status QUERY (options)
118 
119 ** TAG COMMANDS **
120 knife tag create NODE TAG ...
121 knife tag delete NODE TAG ...
122 knife tag list NODE

Wow. That’s a lot of options! Take notice of lines 50-51:

knife cookbook github compare COOKBOOK [USER/BRANCH] (options)
knife cookbook github install USER/REPO [USER/REPO/BRANCH] (options)

Those were added by the knife-github-cookbooks gem we installed earlier.

Before we continue on to adding cookbooks from github, we need to make sure all files in our project repository are comitted. If we don’t, the plugin will fail to install cookbooks into our local git repository due to “uncomitted changes”:

1 $ git add .
2 $ git commit -m "Installed Chef. Configured Knife."
3 [master 5834d35] Installed Chef. Configured Knife.
4  3 files changed, 66 insertions(+)
5  create mode 100644 .chef/knife.rb
6  

Import Cookbooks from GitHub

Before we import our first cookbook from github, let’s talk a little about what it’s going to do, and why. In the past, cookbooks, specifically OpsCode cookbooks were all in one big repository. To use a cookbook, you essentually had to copy it into your project and customize it, which left you somewhat detached and unaware of updates to the cookbook upstream in github. Some people would fork (a GitHub copy) a cookbook into their own account and customize it, and maybe that’s the one you wanted to use instead of the OpsCode verision.

Then along came knife-github-cookbooks along with OpsCode splitting each cookbook into it’s own separate github repository. Now when you add a cookbook using this plugin, it will add the remote repository to your product repository, make a chef-vendor-cookbookname branch for it, and then merge it back into your main (master) branch. To customize your cookbook, simply make change to master like you would any other file. To update the cookbook from the OpsCode repository, update the chef-vendor-cookbookname branch from the remote server, then merge those changes back into your master branch.

With that, let’s add our first cookbook, build-essential from here: :https://github.com/opscode-cookbooks/build-essential. This cookbook is required by almost all other cookbooks.

When using the github install option to knife cookbook, all it needs to know is the user/repo part of the github path, in this case opscode-cookbooks/build-essential:

 1 $ knife cookbook github install opscode-cookbooks/build-essential
 2 Installing build-essential from git://github.com/opscode-cookbooks/build-essential.git to /Users/claco/OLF2012/chef/cookbooks
 3 Checking out the master branch.
 4 Creating pristine copy branch chef-vendor-build-essential
 5 Removing pre-existing version.
 6 Found master amoung heads.
 7 1 files updated, committing changes
 8 Creating tag cookbook-site-imported-build-essential-0b47bc690e9100fdabd8bc87376725cec90eab83
 9 Checking out the master branch.
10 Updating 5fa4628..8c17bcb
11 Fast-forward
12  chef/cookbooks/build-essential/CHANGELOG.md          |  11 +++++
13  chef/cookbooks/build-essential/CONTRIBUTING          |  29 ++++++++++++
14  chef/cookbooks/build-essential/LICENSE               | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15  chef/cookbooks/build-essential/README.md             | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++
16  chef/cookbooks/build-essential/attributes/default.rb |  32 ++++++++++++++
17  chef/cookbooks/build-essential/metadata.rb           |  12 +++++
18  chef/cookbooks/build-essential/recipes/default.rb    |  79 +++++++++++++++++++++++++++++++++
19  7 files changed, 488 insertions(+)
20  create mode 100644 chef/cookbooks/build-essential/CHANGELOG.md
21  create mode 100644 chef/cookbooks/build-essential/CONTRIBUTING
22  create mode 100644 chef/cookbooks/build-essential/LICENSE
23  create mode 100644 chef/cookbooks/build-essential/README.md
24  create mode 100644 chef/cookbooks/build-essential/attributes/default.rb
25  create mode 100644 chef/cookbooks/build-essential/metadata.rb
26  create mode 100644 chef/cookbooks/build-essential/recipes/default.rb
27 Cookbook build-essential version 0b47bc690e9100fdabd8bc87376725cec90eab83 successfully installed

Just to verify what just happened, you should now have a chef/cookbooks/build-essential folder, a chef-vendor-build-essential branch in git, and a commit in git log:

$ ls chef/cookbooks
total 0
drwxr-xr-x  9 claco  staff  306 Sep 25 14:34 build-essential

$ git branch -l
  chef-vendor-build-essential
* master

$ git log -n 1
commit 6912b477ce8e0636c61b5fc685659a0d8e46edf5
Author: Christopher H. Laco <claco@chrislaco.com>
Date:   Tue Sep 25 14:34:39 2012 -0400

    Import opscode-cookbooks/build-essential version 973f97efc279780c0f3de027bb020a1615a9f84d

Now, repeat the above process for apache2, passenger_apache2, openssl, and mysql:

1 knife cookbook github install opscode-cookbooks/apache2
2 knife cookbook github install opscode-cookbooks/passenger_apache2
3 knife cookbook github install opscode-cookbooks/openssl
4 knife cookbook github install opscode-cookbooks/mysql

When you’re all done, you should have something that looks like this:

 1 .
 2 ├── .chef
 3 ├── boxes
 4 ├── chef
 5 │   ├── cookbooks
 6 │   │   ├── apache2
 7 │   │   ├── build-essential
 8 │   │   ├── mysql
 9 │   │   ├── openssl
10 │   │   └── passenger_apache2
11 │   ├── data_bags
12 │   ├── environments
13 │   └── roles
14 ├── definitions
15 │   └── MyServer
16 ├── instances
17 │   └── cluster
18 └── iso

Create Web/DB Roles

Now that we’ve loaded some cookbooks, let’s create two “roles”; one for the web instance and one for the db instance. A role is simply a group of cookbooks/recipes and possibly other roles, grouped together by name. Then later, we can assign the role to an instance rather than manually assigning all of the individual recipes.

In your editor, create an open a new file in chef/roles/db.rb:

1 name "db"
2 description "Database Server Role"
3 run_list(
4   "recipe[mysql::server]"
5 )

From the top: For the db role, we assign a name, give it a description, then give it a “run list”. The run list tells Chef what individual recipes within our cookbooks to run. In this case, we just want to install MySql Server.

Now lets create the web role. In your editor, create an open a new file in chef/roles/db.rb:

1 name "web"
2 description "Web Server Role"
3 run_list(
4   "recipe[apache2]", \
5   "recipe[passenger_apache2::mod_rails]", \
6   "recipe[mysql::client]"
7 )

From the top: Just as the db role, we give it a name, description and a run list. In this role, we want to install Apache, Passenger, and the MySql Client.

Configure Chef Solo in Vagrantfile

Now that we have loaded some cookbooks with recipes, and created a few roles, we need to edit our Vagrantfile to have Chef Solo run and install the software we’ve asked for.

Go ahead and change to the instances/cluster directory and open Vagrantfile in your editor:

1 $ cd instances/cluster

Where we defined our instances at the bottom of the file, we’re going to add a block of code that enables the :chef_solo provisioner, tells it where to find the cookbooks and roles relative to the current Vagrantfile, and what role to run. For the web_config block, we’re also going to map port 8010 on localhost to port 80 inside of the web instance so we can test our apache install.

 1 config.vm.define :web do |web_config|
 2   web_config.vm.host_name = "web"
 3   web_config.vm.network :hostonly, "10.10.10.10"
 4   web_config.vm.forward_port 22, 2210
 5   web_config.vm.forward_port 80, 8010
 6 
 7   web_config.vm.provision :chef_solo do |chef|
 8     chef.cookbooks_path = "../../chef/cookbooks"
 9     chef.roles_path     = "../../chef/roles"
10     chef.add_role "web"
11   end
12 end
13 
14 config.vm.define :db do |db_config|
15   db_config.vm.host_name = "db"                                                                                                            
16   db_config.vm.network :hostonly, "10.10.10.11"
17   db_config.vm.forward_port 22, 2211    
18 
19   db_config.vm.provision :chef_solo do |chef|
20     chef.cookbooks_path = "../../chef/cookbooks"
21     chef.roles_path     = "../../chef/roles"
22     chef.add_role "db"
23   end
24 end

Provision the Instances

Now that we’ve added cookbooks, defined roles, and configured vagrant to run Chef Solo when the instance boots, let’s watch the magic happen. First let’s start the database instance:

 1 $ vagrant up db
 2 [db] Importing base box 'MyServer'...
 3 [db] Matching MAC address for NAT networking...
 4 [db] Clearing any previously set forwarded ports...
 5 [db] Forwarding ports...
 6 [db] -- 22 => 2211 (adapter 1)
 7 [db] Creating shared folders metadata...
 8 [db] Clearing any previously set network interfaces...
 9 [db] Preparing network interfaces based on configuration...
10 [db] Booting VM...
11 [db] Waiting for VM to boot. This can take a few minutes.
12 [db] VM booted and ready for use!
13 [db] Configuring and enabling network interfaces...
14 [db] Setting host name...
15 [db] Mounting shared folders...
16 [db] -- v-root: /vagrant
17 [db] -- v-csr-2: /tmp/vagrant-chef-1/chef-solo-2/roles
18 [db] -- v-csc-1: /tmp/vagrant-chef-1/chef-solo-1/cookbooks
19 [db] Running provisioner: Vagrant::Provisioners::ChefSolo...
20 [db] Generating chef JSON and uploading...
21 [db] Running chef-solo...
22 [2012-09-26T00:38:26+01:00] INFO: *** Chef 10.12.0 ***
23 [2012-09-26T00:38:27+01:00] INFO: Setting the run_list to ["role[db]"] from JSON
24 [2012-09-26T00:38:27+01:00] INFO: Run List is [role[db]]
25 [2012-09-26T00:38:27+01:00] INFO: Run List expands to [mysql::server]
26 [2012-09-26T00:38:27+01:00] INFO: Starting Chef Run for db
27 [2012-09-26T00:38:27+01:00] INFO: Running start handlers
28 [2012-09-26T00:38:27+01:00] INFO: Start handlers complete.
29 [2012-09-26T00:38:27+01:00] INFO: Could not find previously defined grants.sql resource
30 [2012-09-26T00:38:27+01:00] INFO: Processing package[mysql] action install (mysql::client line 46)
31 [2012-09-26T00:38:49+01:00] INFO: package[mysql] installing mysql-5.0.95-1.el5_7.1 from updates repository
32 [2012-09-26T00:40:11+01:00] INFO: package[mysql] installed version 5.0.95-1.el5_7.1
33 [2012-09-26T00:40:11+01:00] INFO: Processing package[mysql-devel] action install (mysql::client line 46)
34 [2012-09-26T00:40:12+01:00] INFO: package[mysql-devel] installing mysql-devel-5.0.95-1.el5_7.1 from updates repository
35 [2012-09-26T00:40:48+01:00] INFO: package[mysql-devel] installed version 5.0.95-1.el5_7.1
36 [2012-09-26T00:40:48+01:00] INFO: Processing package[mysql-server] action install (mysql::server line 78)
37 [2012-09-26T00:40:49+01:00] INFO: package[mysql-server] installing mysql-server-5.0.95-1.el5_7.1 from updates repository
38 [2012-09-26T00:41:24+01:00] INFO: package[mysql-server] installed version 5.0.95-1.el5_7.1
39 [2012-09-26T00:41:24+01:00] INFO: Processing directory[/etc/mysql/conf.d] action create (mysql::server line 85)
40 [2012-09-26T00:41:24+01:00] INFO: directory[/etc/mysql/conf.d] created directory /etc/mysql/conf.d
41 [2012-09-26T00:41:24+01:00] INFO: directory[/etc/mysql/conf.d] owner changed to 27
42 [2012-09-26T00:41:24+01:00] INFO: directory[/etc/mysql/conf.d] group changed to 27
43 [2012-09-26T00:41:24+01:00] INFO: Processing service[mysql] action enable (mysql::server line 105)
44 [2012-09-26T00:41:25+01:00] INFO: service[mysql] enabled
45 [2012-09-26T00:41:25+01:00] INFO: Processing template[/etc/my.cnf] action create (mysql::server line 125)
46 [2012-09-26T00:41:25+01:00] INFO: template[/etc/my.cnf] backed up to /var/chef/backup/etc/my.cnf.chef-20120926004125
47 [2012-09-26T00:41:25+01:00] INFO: template[/etc/my.cnf] mode changed to 644
48 [2012-09-26T00:41:25+01:00] INFO: template[/etc/my.cnf] updated content
49 [2012-09-26T00:41:25+01:00] INFO: template[/etc/my.cnf] sending restart action to service[mysql] (immediate)
50 [2012-09-26T00:41:25+01:00] INFO: Processing service[mysql] action restart (mysql::server line 105)
51 [2012-09-26T00:41:26+01:00] INFO: service[mysql] restarted
52 [2012-09-26T00:41:26+01:00] INFO: Processing execute[assign-root-password] action run (mysql::server line 153)
53 [2012-09-26T00:41:26+01:00] INFO: execute[assign-root-password] ran successfully
54 [2012-09-26T00:41:26+01:00] INFO: Processing template[/etc/mysql_grants.sql] action create (mysql::server line 175)
55 [2012-09-26T00:41:26+01:00] INFO: template[/etc/mysql_grants.sql] updated content
56 [2012-09-26T00:41:26+01:00] INFO: template[/etc/mysql_grants.sql] sending run action to execute[mysql-install-privileges] (immediate)
57 [2012-09-26T00:41:26+01:00] INFO: Processing execute[mysql-install-privileges] action run (mysql::server line 191)
58 [2012-09-26T00:41:26+01:00] INFO: execute[mysql-install-privileges] ran successfully
59 [2012-09-26T00:41:26+01:00] INFO: Processing execute[mysql-install-privileges] action nothing (mysql::server line 191)
60 [2012-09-26T00:41:26+01:00] INFO: Chef Run complete in 179.143542 seconds
61 [2012-09-26T00:41:26+01:00] INFO: Running report handlers
62 [2012-09-26T00:41:26+01:00] INFO: Report handlers complete

From the top: Lines 2-14, the MyServer box is imported, instance created and booted up. Lines 15-21, vagrant maps shared folders containing the cooksbooks and roles to be loaded. Line 22+, Chef expands the db role into recipes, runs the recipes and installs MySQL server.

Let’s login and look around in our db instance.

 1 $ vagrant ssh db
 2 Last login: Wed Sep 26 00:48:04 2012 from 10.0.2.2
 3 
 4 [vagrant@db ~]$ sudo /sbin/service mysqld status
 5 mysqld (pid 5522) is running...
 6 
 7 [vagrant@db ~]$ mysql -u root
 8 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
 9 
10 [vagrant@db ~]$ mysql -u root -p
11 Enter password: 
12 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
13 
14 [vagrant@db ~]$ grep bind /etc/my.cnf
15 bind-address            = 10.0.2.15
16 
17 [vagrant@db ~]$ sudo /sbin/chkconfig --list mysqld
18 mysqld         	0:off	1:off	2:off	3:off	4:off	5:off	6:off
19 
20 [vagrant@db ~]$ exit
21 
22 # if you don't have mysql installed locally, try:  telnet 10.0.2.15 3306
23 mysql -u root -p -h 10.0.2.15
24 Enter password: 
25 ERROR 2003 (HY000): Can't connect to MySQL server on '10.0.2.15' (61)

From the top: Once logged in, we check the service status. mysqld is running! Try logging in using mysql. No blank root password. Unfortunately, we don’t know the randomly generated password either. Finally, mysql is bound to the first ip address it found, which is not 10.10.10.11 we assiend in Vagrantfile. But, MySQL is installed! Once logged out, we try logging into mysql externally. “Can’t connect” instead of “Access denied” means the firewall on the instance itself is also blocking our access.

From the trenches: Just as another example of how you never know what might happen with older os installations and packages. The yum install of mysql and/or cookbook doesn’t configure the mysqld service to automatically start after boot. Boo! If you were to reboot your instance and try to rerun mysql related recipes, they would fail because the service isn’t running. It may even be fixed in the cookbook by the time you are reading this. :-)

While we don’t have a very useful MySQL server, we did just use Chef Solo to install a working copy of MySSQL. In the next part of the guide, we’ll customze the cookbooks and vagrant to bind to our ip, set a know root password, created databases and open up the firewall so the web instance cal talk to it.

Now let’s provision the web instance:

  1 $ vagrant up web
  2 [web] Importing base box 'MyServer'...
  3 [web] Matching MAC address for NAT networking...
  4 [web] Clearing any previously set forwarded ports...
  5 [web] Forwarding ports...
  6 [web] -- 22 => 2210 (adapter 1)
  7 [web] -- 80 => 8010 (adapter 1)
  8 [web] Creating shared folders metadata...
  9 [web] Clearing any previously set network interfaces...
 10 [web] Preparing network interfaces based on configuration...
 11 [web] Booting VM...
 12 [web] Waiting for VM to boot. This can take a few minutes.
 13 [web] VM booted and ready for use!
 14 [web] Configuring and enabling network interfaces...
 15 [web] Setting host name...
 16 [web] Mounting shared folders...
 17 [web] -- v-root: /vagrant
 18 [web] -- v-csr-2: /tmp/vagrant-chef-1/chef-solo-2/roles
 19 [web] -- v-csc-1: /tmp/vagrant-chef-1/chef-solo-1/cookbooks
 20 [web] Running provisioner: Vagrant::Provisioners::ChefSolo...
 21 [web] Generating chef JSON and uploading...
 22 [web] Running chef-solo...
 23 [2012-09-26T01:22:42+01:00] INFO: *** Chef 10.12.0 ***
 24 [2012-09-26T01:22:43+01:00] INFO: Setting the run_list to ["role[web]"] from JSON
 25 [2012-09-26T01:22:43+01:00] INFO: Run List is [role[web]]
 26 [2012-09-26T01:22:43+01:00] INFO: Run List expands to [apache2, passenger_apache2::mod_rails, mysql::client]
 27 [2012-09-26T01:22:43+01:00] INFO: Starting Chef Run for web
 28 [2012-09-26T01:22:43+01:00] INFO: Running start handlers
 29 [2012-09-26T01:22:43+01:00] INFO: Start handlers complete.
 30 [2012-09-26T01:22:43+01:00] INFO: Processing package[apache2] action install (apache2::default line 20)
 31 [2012-09-26T01:23:13+01:00] INFO: package[apache2] installing httpd-2.2.3-65.el5.centos from updates repository
 32 [2012-09-26T01:23:46+01:00] INFO: package[apache2] installed version 2.2.3-65.el5.centos
 33 [2012-09-26T01:23:46+01:00] INFO: Processing service[apache2] action enable (apache2::default line 25)
 34 [2012-09-26T01:23:46+01:00] INFO: service[apache2] enabled
 35 [2012-09-26T01:23:46+01:00] INFO: Processing directory[/var/log/httpd] action create (apache2::default line 60)
 36 [2012-09-26T01:23:46+01:00] INFO: directory[/var/log/httpd] mode changed to 755
 37 [2012-09-26T01:23:46+01:00] INFO: Processing package[perl] action install (apache2::default line 65)
 38 [2012-09-26T01:23:46+01:00] INFO: Processing cookbook_file[/usr/local/bin/apache2_module_conf_generate.pl] action create (apache2::default line 67)
 39 [2012-09-26T01:23:46+01:00] INFO: cookbook_file[/usr/local/bin/apache2_module_conf_generate.pl] mode changed to 755
 40 [2012-09-26T01:23:46+01:00] INFO: cookbook_file[/usr/local/bin/apache2_module_conf_generate.pl] created file /usr/local/bin/apache2_module_conf_generate.pl
 41 [2012-09-26T01:23:46+01:00] INFO: Processing directory[/etc/httpd/sites-available] action create (apache2::default line 75)
 42 [2012-09-26T01:23:46+01:00] INFO: directory[/etc/httpd/sites-available] created directory /etc/httpd/sites-available
 43 [2012-09-26T01:23:46+01:00] INFO: Processing directory[/etc/httpd/sites-enabled] action create (apache2::default line 75)
 44 [2012-09-26T01:23:46+01:00] INFO: directory[/etc/httpd/sites-enabled] created directory /etc/httpd/sites-enabled
 45 [2012-09-26T01:23:46+01:00] INFO: Processing directory[/etc/httpd/mods-available] action create (apache2::default line 75)
 46 [2012-09-26T01:23:46+01:00] INFO: directory[/etc/httpd/mods-available] created directory /etc/httpd/mods-available
 47 [2012-09-26T01:23:46+01:00] INFO: Processing directory[/etc/httpd/mods-enabled] action create (apache2::default line 75)
 48 [2012-09-26T01:23:46+01:00] INFO: directory[/etc/httpd/mods-enabled] created directory /etc/httpd/mods-enabled
 49 [2012-09-26T01:23:46+01:00] INFO: Processing execute[generate-module-list] action run (apache2::default line 83)
 50 [2012-09-26T01:23:46+01:00] INFO: execute[generate-module-list] ran successfully
 51 [2012-09-26T01:23:46+01:00] INFO: Processing template[/usr/sbin/a2ensite] action create (apache2::default line 89)
 52 [2012-09-26T01:23:46+01:00] INFO: template[/usr/sbin/a2ensite] mode changed to 700
 53 [2012-09-26T01:23:46+01:00] INFO: template[/usr/sbin/a2ensite] updated content
 54 [2012-09-26T01:23:46+01:00] INFO: Processing template[/usr/sbin/a2dissite] action create (apache2::default line 89)
 55 [2012-09-26T01:23:46+01:00] INFO: template[/usr/sbin/a2dissite] mode changed to 700
 56 [2012-09-26T01:23:46+01:00] INFO: template[/usr/sbin/a2dissite] updated content
 57 [2012-09-26T01:23:46+01:00] INFO: Processing template[/usr/sbin/a2enmod] action create (apache2::default line 89)
 58 [2012-09-26T01:23:46+01:00] INFO: template[/usr/sbin/a2enmod] mode changed to 700
 59 [2012-09-26T01:23:46+01:00] INFO: template[/usr/sbin/a2enmod] updated content
 60 [2012-09-26T01:23:46+01:00] INFO: Processing template[/usr/sbin/a2dismod] action create (apache2::default line 89)
 61 [2012-09-26T01:23:46+01:00] INFO: template[/usr/sbin/a2dismod] mode changed to 700
 62 [2012-09-26T01:23:46+01:00] INFO: template[/usr/sbin/a2dismod] updated content
 63 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/conf.d/proxy_ajp.conf] action delete (apache2::default line 99)
 64 [2012-09-26T01:23:46+01:00] INFO: file[/etc/httpd/conf.d/proxy_ajp.conf] deleted file at /etc/httpd/conf.d/proxy_ajp.conf
 65 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/conf.d/auth_pam.conf] action delete (apache2::default line 99)
 66 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/conf.d/authz_ldap.conf] action delete (apache2::default line 99)
 67 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/conf.d/webalizer.conf] action delete (apache2::default line 99)
 68 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/conf.d/ssl.conf] action delete (apache2::default line 99)
 69 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/conf.d/welcome.conf] action delete (apache2::default line 99)
 70 [2012-09-26T01:23:46+01:00] INFO: file[/etc/httpd/conf.d/welcome.conf] deleted file at /etc/httpd/conf.d/welcome.conf
 71 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/conf.d/README] action delete (apache2::default line 106)
 72 [2012-09-26T01:23:46+01:00] INFO: file[/etc/httpd/conf.d/README] deleted file at /etc/httpd/conf.d/README
 73 [2012-09-26T01:23:46+01:00] INFO: Processing template[/etc/httpd/mods-available/deflate.conf] action create (apache2::mod_deflate line 21)
 74 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/deflate.conf] mode changed to 644
 75 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/deflate.conf] updated content
 76 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/mods-available/deflate.load] action create (apache2::mod_deflate line 31)
 77 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2enmod deflate] action run (apache2::mod_deflate line 38)
 78 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod deflate] ran successfully
 79 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod deflate] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
 80 [2012-09-26T01:23:46+01:00] INFO: Processing directory[/etc/httpd/ssl] action create (apache2::default line 138)
 81 [2012-09-26T01:23:46+01:00] INFO: directory[/etc/httpd/ssl] created directory /etc/httpd/ssl
 82 [2012-09-26T01:23:46+01:00] INFO: Processing directory[/etc/httpd/conf.d] action create (apache2::default line 145)
 83 [2012-09-26T01:23:46+01:00] INFO: Processing directory[/var/cache/httpd] action create (apache2::default line 152)
 84 [2012-09-26T01:23:46+01:00] INFO: directory[/var/cache/httpd] created directory /var/cache/httpd
 85 [2012-09-26T01:23:46+01:00] INFO: Processing template[apache2.conf] action create (apache2::default line 159)
 86 [2012-09-26T01:23:46+01:00] INFO: template[apache2.conf] backed up to /var/chef/backup/etc/httpd/conf/httpd.conf.chef-20120926012346
 87 [2012-09-26T01:23:46+01:00] INFO: template[apache2.conf] mode changed to 644
 88 [2012-09-26T01:23:46+01:00] INFO: template[apache2.conf] updated content
 89 [2012-09-26T01:23:46+01:00] INFO: template[apache2.conf] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
 90 [2012-09-26T01:23:46+01:00] INFO: Processing template[security] action create (apache2::default line 175)
 91 [2012-09-26T01:23:46+01:00] INFO: template[security] mode changed to 644
 92 [2012-09-26T01:23:46+01:00] INFO: template[security] updated content
 93 [2012-09-26T01:23:46+01:00] INFO: template[security] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
 94 [2012-09-26T01:23:46+01:00] INFO: Processing template[charset] action create (apache2::default line 185)
 95 [2012-09-26T01:23:46+01:00] INFO: template[charset] mode changed to 644
 96 [2012-09-26T01:23:46+01:00] INFO: template[charset] updated content
 97 [2012-09-26T01:23:46+01:00] INFO: template[charset] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
 98 [2012-09-26T01:23:46+01:00] INFO: Processing template[/etc/httpd/ports.conf] action create (apache2::default line 195)
 99 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/ports.conf] mode changed to 644
100 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/ports.conf] updated content
101 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/ports.conf] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
102 [2012-09-26T01:23:46+01:00] INFO: Processing template[/etc/httpd/sites-available/default] action create (apache2::default line 204)
103 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/sites-available/default] mode changed to 644
104 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/sites-available/default] updated content
105 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/sites-available/default] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
106 [2012-09-26T01:23:46+01:00] INFO: Processing template[/etc/httpd/mods-available/status.conf] action create (apache2::mod_status line 21)
107 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/status.conf] mode changed to 644
108 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/status.conf] updated content
109 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/status.conf] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
110 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/mods-available/status.load] action create (apache2::mod_status line 31)
111 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2enmod status] action run (apache2::mod_status line 38)
112 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod status] ran successfully
113 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod status] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
114 [2012-09-26T01:23:46+01:00] INFO: Processing template[/etc/httpd/mods-available/alias.conf] action create (apache2::mod_alias line 21)
115 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/alias.conf] mode changed to 644
116 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/alias.conf] updated content
117 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/alias.conf] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
118 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/mods-available/alias.load] action create (apache2::mod_alias line 31)
119 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2enmod alias] action run (apache2::mod_alias line 38)
120 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod alias] ran successfully
121 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod alias] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
122 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/mods-available/auth_basic.load] action create (apache2::mod_auth_basic line 31)
123 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2enmod auth_basic] action run (apache2::mod_auth_basic line 38)
124 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod auth_basic] ran successfully
125 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod auth_basic] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
126 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/mods-available/authn_file.load] action create (apache2::mod_authn_file line 31)
127 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2enmod authn_file] action run (apache2::mod_authn_file line 38)
128 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod authn_file] ran successfully
129 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod authn_file] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
130 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/mods-available/authz_default.load] action create (apache2::mod_authz_default line 31)
131 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2enmod authz_default] action run (apache2::mod_authz_default line 38)
132 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod authz_default] ran successfully
133 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod authz_default] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
134 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/mods-available/authz_groupfile.load] action create (apache2::mod_authz_groupfile line 31)
135 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2enmod authz_groupfile] action run (apache2::mod_authz_groupfile line 38)
136 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod authz_groupfile] ran successfully
137 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod authz_groupfile] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
138 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/mods-available/authz_host.load] action create (apache2::mod_authz_host line 31)
139 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2enmod authz_host] action run (apache2::mod_authz_host line 38)
140 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod authz_host] ran successfully
141 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod authz_host] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
142 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/mods-available/authz_user.load] action create (apache2::mod_authz_user line 31)
143 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2enmod authz_user] action run (apache2::mod_authz_user line 38)
144 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod authz_user] ran successfully
145 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod authz_user] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
146 [2012-09-26T01:23:46+01:00] INFO: Processing template[/etc/httpd/mods-available/autoindex.conf] action create (apache2::mod_autoindex line 21)
147 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/autoindex.conf] mode changed to 644
148 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/autoindex.conf] updated content
149 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/autoindex.conf] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
150 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/mods-available/autoindex.load] action create (apache2::mod_autoindex line 31)
151 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2enmod autoindex] action run (apache2::mod_autoindex line 38)
152 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod autoindex] ran successfully
153 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod autoindex] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
154 [2012-09-26T01:23:46+01:00] INFO: Processing template[/etc/httpd/mods-available/dir.conf] action create (apache2::mod_dir line 21)
155 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/dir.conf] mode changed to 644
156 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/dir.conf] updated content
157 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/dir.conf] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
158 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/mods-available/dir.load] action create (apache2::mod_dir line 31)
159 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2enmod dir] action run (apache2::mod_dir line 38)
160 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod dir] ran successfully
161 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod dir] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
162 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/mods-available/env.load] action create (apache2::mod_env line 31)
163 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2enmod env] action run (apache2::mod_env line 38)
164 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod env] ran successfully
165 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod env] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
166 [2012-09-26T01:23:46+01:00] INFO: Processing template[/etc/httpd/mods-available/mime.conf] action create (apache2::mod_mime line 21)
167 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/mime.conf] mode changed to 644
168 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/mime.conf] updated content
169 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/mime.conf] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
170 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/mods-available/mime.load] action create (apache2::mod_mime line 31)
171 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2enmod mime] action run (apache2::mod_mime line 38)
172 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod mime] ran successfully
173 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod mime] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
174 [2012-09-26T01:23:46+01:00] INFO: Processing template[/etc/httpd/mods-available/negotiation.conf] action create (apache2::mod_negotiation line 21)
175 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/negotiation.conf] mode changed to 644
176 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/negotiation.conf] updated content
177 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/negotiation.conf] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
178 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/mods-available/negotiation.load] action create (apache2::mod_negotiation line 31)
179 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2enmod negotiation] action run (apache2::mod_negotiation line 38)
180 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod negotiation] ran successfully
181 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod negotiation] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
182 [2012-09-26T01:23:46+01:00] INFO: Processing template[/etc/httpd/mods-available/setenvif.conf] action create (apache2::mod_setenvif line 21)
183 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/setenvif.conf] mode changed to 644
184 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/setenvif.conf] updated content
185 [2012-09-26T01:23:46+01:00] INFO: template[/etc/httpd/mods-available/setenvif.conf] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
186 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/mods-available/setenvif.load] action create (apache2::mod_setenvif line 31)
187 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2enmod setenvif] action run (apache2::mod_setenvif line 38)
188 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod setenvif] ran successfully
189 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod setenvif] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
190 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/mods-available/log_config.load] action create (apache2::mod_log_config line 31)
191 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2enmod log_config] action run (apache2::mod_log_config line 38)
192 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod log_config] ran successfully
193 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod log_config] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
194 [2012-09-26T01:23:46+01:00] INFO: Processing file[/etc/httpd/mods-available/logio.load] action create (apache2::mod_logio line 31)
195 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2enmod logio] action run (apache2::mod_logio line 38)
196 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod logio] ran successfully
197 [2012-09-26T01:23:46+01:00] INFO: execute[a2enmod logio] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
198 [2012-09-26T01:23:46+01:00] INFO: Processing execute[a2ensite default] action run (apache2::default line 24)
199 [2012-09-26T01:23:46+01:00] INFO: execute[a2ensite default] ran successfully
200 [2012-09-26T01:23:46+01:00] INFO: execute[a2ensite default] not queuing delayed action restart on service[apache2] (delayed), as it's already been queued
201 [2012-09-26T01:23:46+01:00] INFO: Processing service[apache2] action start (apache2::default line 219)
202 [2012-09-26T01:23:46+01:00] INFO: service[apache2] started
203 [2012-09-26T01:23:46+01:00] INFO: Processing package[gcc] action install (build-essential::default line 48)
204 [2012-09-26T01:23:46+01:00] INFO: Processing package[gcc-c++] action install (build-essential::default line 48)
205 [2012-09-26T01:23:46+01:00] INFO: Processing package[kernel-devel] action install (build-essential::default line 48)
206 [2012-09-26T01:23:46+01:00] INFO: Processing package[make] action install (build-essential::default line 48)
207 [2012-09-26T01:23:46+01:00] INFO: Processing package[autoconf] action install (build-essential::default line 55)
208 [2012-09-26T01:23:46+01:00] INFO: package[autoconf] installing autoconf-2.59-12 from base repository
209 [2012-09-26T01:23:51+01:00] INFO: package[autoconf] installed version 2.59-12
210 [2012-09-26T01:23:51+01:00] INFO: Processing package[flex] action install (build-essential::default line 55)
211 [2012-09-26T01:23:51+01:00] INFO: package[flex] installing flex-2.5.4a-41.fc6 from base repository
212 [2012-09-26T01:23:53+01:00] INFO: package[flex] installed version 2.5.4a-41.fc6
213 [2012-09-26T01:23:53+01:00] INFO: Processing package[bison] action install (build-essential::default line 55)
214 [2012-09-26T01:23:54+01:00] INFO: package[bison] installing bison-2.3-2.1 from base repository
215 [2012-09-26T01:23:57+01:00] INFO: package[bison] installed version 2.3-2.1
216 [2012-09-26T01:23:57+01:00] INFO: Processing package[httpd-devel] action install (passenger_apache2::default line 32)
217 [2012-09-26T01:23:57+01:00] INFO: package[httpd-devel] installing httpd-devel-2.2.3-65.el5.centos from updates repository
218 [2012-09-26T01:24:27+01:00] INFO: package[httpd-devel] installed version 2.2.3-65.el5.centos
219 [2012-09-26T01:24:27+01:00] INFO: Processing package[curl-devel] action install (passenger_apache2::default line 34)
220 [2012-09-26T01:24:27+01:00] INFO: package[curl-devel] installing curl-devel-7.15.5-15.el5 from base repository
221 [2012-09-26T01:24:47+01:00] INFO: package[curl-devel] installed version 7.15.5-15.el5
222 [2012-09-26T01:24:47+01:00] INFO: Processing gem_package[passenger] action install (passenger_apache2::default line 48)
223 [2012-09-26T01:25:24+01:00] INFO: gem_package[passenger] installed version 3.0.11
224 [2012-09-26T01:25:24+01:00] INFO: Processing execute[passenger_module] action run (passenger_apache2::default line 52)
225 [2012-09-26T01:26:06+01:00] INFO: execute[passenger_module] ran successfully
226 [2012-09-26T01:26:06+01:00] INFO: Processing template[/etc/httpd/mods-available/passenger.conf] action create (passenger_apache2::mod_rails line 37)
227 [2012-09-26T01:26:06+01:00] INFO: template[/etc/httpd/mods-available/passenger.conf] mode changed to 644
228 [2012-09-26T01:26:06+01:00] INFO: template[/etc/httpd/mods-available/passenger.conf] updated content
229 [2012-09-26T01:26:06+01:00] INFO: Processing file[/etc/httpd/mods-available/passenger.load] action create (passenger_apache2::mod_rails line 31)
230 [2012-09-26T01:26:06+01:00] INFO: file[/etc/httpd/mods-available/passenger.load] created file /etc/httpd/mods-available/passenger.load
231 [2012-09-26T01:26:06+01:00] INFO: Processing execute[a2enmod passenger] action run (passenger_apache2::mod_rails line 38)
232 [2012-09-26T01:26:06+01:00] INFO: execute[a2enmod passenger] ran successfully
233 [2012-09-26T01:26:06+01:00] INFO: Processing package[mysql] action install (mysql::client line 46)
234 [2012-09-26T01:26:06+01:00] INFO: package[mysql] installing mysql-5.0.95-1.el5_7.1 from updates repository
235 [2012-09-26T01:26:35+01:00] INFO: package[mysql] installed version 5.0.95-1.el5_7.1
236 [2012-09-26T01:26:35+01:00] INFO: Processing package[mysql-devel] action install (mysql::client line 46)
237 [2012-09-26T01:26:36+01:00] INFO: package[mysql-devel] installing mysql-devel-5.0.95-1.el5_7.1 from updates repository
238 [2012-09-26T01:27:18+01:00] INFO: package[mysql-devel] installed version 5.0.95-1.el5_7.1
239 [2012-09-26T01:27:18+01:00] INFO: template[/etc/httpd/mods-available/deflate.conf] sending restart action to service[apache2] (delayed)
240 [2012-09-26T01:27:18+01:00] INFO: Processing service[apache2] action restart (apache2::default line 25)
241 [2012-09-26T01:27:19+01:00] INFO: service[apache2] restarted
242 [2012-09-26T01:27:19+01:00] INFO: execute[a2enmod passenger] sending restart action to service[apache2] (delayed)
243 [2012-09-26T01:27:19+01:00] INFO: Processing service[apache2] action restart (apache2::default line 219)
244 [2012-09-26T01:27:20+01:00] INFO: service[apache2] restarted
245 [2012-09-26T01:27:20+01:00] INFO: Chef Run complete in 277.48792 seconds
246 [2012-09-26T01:27:20+01:00] INFO: Running report handlers
247 [2012-09-26T01:27:20+01:00] INFO: Report handlers complete

From the top: Lines 2-14, the MyServer box is imported, instance created and booted up. Lines 15-21, vagrant maps shared folders containing the cooksbooks and roles to be loaded. Line 22+, Chef expands the web role into recipes, runs the recipes and installs Apache, Passenger, and the MySQL Client.

Let’s login and look around in our web instance.

 1 $ vagrant ssh web
 2 Last login: Sun Sep  2 18:51:55 2012 from 10.0.2.2
 3 
 4 [vagrant@web ~]$ sudo /sbin/service httpd status
 5 httpd (pid  8796) is running...
 6 
 7 [vagrant@web mods-enabled]$ cat /etc/httpd/mods-enabled/passenger.conf
 8 PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.11
 9 PassengerRuby /usr/local/bin/ruby
10 PassengerMaxPoolSize 6
11 
12 [vagrant@web mods-enabled]$ sudo passenger-status
13 ----------- General information -----------
14 max      = 6
15 count    = 0
16 active   = 0
17 inactive = 0
18 Waiting on global queue: 0
19 
20 ----------- Application groups -----------

From the top: Once logged into the web instance, we can see the httpd service is running, the passenger module has been installed and configured to use our ruby, and passenger-status is installed.

If we open up a browser and go to http://localhost:8011, we’ll see a default Apache homepage waiting for us. This is because we’ve asked vagrant to map the port 8011 on the localhost to port 80 inside of the instance.

However, and as expected by now, the firewall on the web instance is blocking us from connecting to apache directly via http://10.10.10.10:80:

Again, like the db instance, in the next part of the guide we’ll customize the cookbooks and settings to open up the firewall and install our application specific website. But, we have just provisioned apache and mysql using Chef Solo! w00t!

For now, again, let’s destroy our instances:

1 $ vagrant destroy
2 Are you sure you want to destroy the 'db' VM? [Y/N] Y
3 [db] Forcing shutdown of VM...
4 [db] Destroying VM and associated drives...
5 Are you sure you want to destroy the 'web' VM? [Y/N] Y
6 [web] Forcing shutdown of VM...
7 [web] Destroying VM and associated drives...

Commit Our Work

Let’s add our update Vagrantfile, roles to the repository.

1 $ cd ../..
2 $ git add .
3 $ git commit -m "Added web/db roles. Added chef solo to Vagrantfile"
4 [master 474a4a8] Added web/db roles. Added chef solo to Vagrantfile.
5  3 files changed, 28 insertions(+), 1 deletion(-)
6  create mode 100644 chef/roles/db.rb
7  create mode 100644 chef/roles/web.rb

To Continue…

  1. Introduction – Introduction
  2. Installing Prerequisites – XCode, CommandLineTools, Homebrew, RVM, Ruby, and VirtualBox
  3. Project Setup – Create the git repository and directory structure for Vagrant, Chef, etc.
  4. Vagrant/Veewee Installation – Install Vagrant/Vewee to create/control VirtualBox machines
  5. Define/Create a Vagrant Box – Define and Create a Vagrant Box for use i VirtualBox
  6. Provisioning Machines with Vagrant – Provision a cluster (Web/DB) of machines using Vagrant
  7. Configuring Machines Using Chef Solo – Configuring our new machine instances using Chef Solo
  8. Customizing Recipes for Our Application – Customize the recipes we have to prepare for our application deployment
  9. Create and Deploy a Rails Applications – Create a simple Rails application and deploy it to our Vagrant instances
  10. Migrate from Chef Solo to Hosted Chef – Migrate from using Chef Solo to hosted Chef at OpsCode
  11. Migrate Servers to RackCloud – Migrate your servers from VirtualBox to “The Cloud” using Rackspace.
See more posts about: devops toolbox | All Categories