In our first installment, I gave an overview of the Chef automation, framework, and terminology and introduced Drupal. Now, let’s install and configure our Chef server, workstation, and client node. First, we need to configure our development machine with the SoftLayer CLI in order to create three virtual servers in SoftLayer. You can also create the virtual servers using the SoftLayer customer portal, if you prefer.
We will use three servers: chef-server-demo, chef-ws-demo, and chef-drupal-demo, each running Ubuntu 12.04 LTS under the domain softlayer.com. Note that you can run the Chef workstation on your development machine as well, but I prefer to keep those separate.
I’m using an Ubuntu 12.04 LTS as my development machine. Let’s install the SoftLayer Python client.
apt-get -y install python-pip pip install softlayer
Now configure the client using sl config setup.
For more information on setting up the SoftLayer Python client, see Getting Started with the Python CLI.
Next, we will create the virtual server for our Chef server. We will use a 100GB local disk and the latest Ubuntu version.
sl cci create --hostname=chef-server-demo --domain=softlayer.com --cpu=1 --memory=1024 --hourly --os=UBUNTU_12_64 --disk=100
Once the provisioning is complete, run sl cci detail where id is the ID of the CCI returned from the step above.
Log in to the Chef server. Ensure that the hostname of your server is a FQDN. Here are detailed instructions for this, or you can run hostname. This should return the FQDN chef-server-demo.softlayer.com. If it does not, run the following command:
sudo hostname chef-server-demo.softlayer.com echo chef-server-demo.softlayer.com | sudo tee /etc/hostname
Follow the Chef install page:
Download the package on your Chef server (using wget, for example). Install the package, using the correct method, on your system. In our example using Ubuntu, the command is dpkg –i xxx.deb.
Once installed, configure the Chef server by running sudo chef-server-ctl reconfigure.
Optionally, you can ensure that the Chef server is configured correctly by running sudo chef-server-ctl test.
As an additional validation step, you can log in to the Chef server UI. The default username and password are located on the right side of the portal.
Chef server portal - Default password on right side
Now, let’s create the virtual server for our Chef workstation. We will use the same CLI command as we did for the Chef server:
sl cci create --hostname=chef-ws-demo --domain=softlayer.com --cpu=1 --memory=1024 --hourly --os=UBUNTU_12_64 --disk=100
You can find detailed instructions on setting up the workstation here.
Log in to the Chef workstation. Ensure that the hostname of the workstation is FQDN, following the same steps as under the Chef server section.
Ensure that the Chef server hostname is resolvable from the workstation server. If it is not, add the host and IP address of the Chef server in the /etc/hosts file.
Next, install the basic packages that will be needed:apt-get –y install curl git vim
Install the Chef-client:
curl -L https://www.opscode.com/chef/install.sh | sudo bash
Once the installation is complete, make sure the Chef-client installed successfully by running:
chef-client –v
You should see the version returned.
Clone the Chef-repo under your home directory using:
git clone git://github.com/opscode/chef-repo.git
Create the .chef directory in order to store the knife.rb file and the required keys using:
mkdir –p ~/chef-repo/.chef
Copy the admin.pem and chef-validator.pem files from the Chef server /etc/chef-server/ directory to the ~/chef-repo/.chef/ folder using:
scp root@chef-server-demo:/etc/chef-server/admin.pem ~/chef-repo/.chef/ scp root@chef-server-demo:/etc/chef-server/chef-validator.pem ~/chef-repo/.chef/
Run the chef-validator utility:
knife configure –initial
This will prompt you to answer several questions, shown here with our example answers:
~/chef-repo/.chef/knife.rbhttps://chef-server-demo.softlayer.com:443;wsadminadmin~/chef-repo/.chef/admin.pemchef-validator~/chef-repo/.chef/chef-validator.pem~/chef-repowsadminVerify that the configuration is correct.
cd ~/chef-repo knife client list
You should get some input back like this:
chef-validator chef-webui
Now, we will install the sendmail cookbook. This cookbook will be needed to properly install Drupal.
knife cookbook site install sendmail
Next, install the Drupal cookbook.
knife cookbook site install drupal
If you’re unlucky like me, you may experience some problems. While writing this blog I hit two issues when deploying the Drupal cookbook on a node, and had to make the following fixes:
vim ~/chef-repo/cookbooks/drupal/templates/default/grants.sql.erb and change the % symbol to localhost such as:GRANT ALL ON .* TO @'localhost' IDENTIFIED BY ;vim ~/chef-repo/cookbooks/drupal/recipes/default.rb and change server_aliases node['fqdn'] to server_aliases [node['fqdn']]Upload the Drupal cookbook to the Chef server:
knife cookbook upload --all
At this point, I have all that I need to start installing Drupal on my nodes.
Bootstrapping the client is the process of installing the Chef-client on the node and starting it. This process will pull the configuration associated with that node from the Chef server.
First, let’s create a virtual server for our client. I will be using the minimum configuration as before.
sl cci create --hostname=chef-drupal-demo --domain=softlayer.com --cpu=1 --memory=1024 --hourly --os=UBUNTU_12_64 --disk=100
Fix the hostname, and include the Chef server hostname in /etc/hosts on the chef-drupal-demo machine.
/etc/hosts for the Chef server.Note: The steps to fix the hostnames are not required if you use a valid DNS service on SoftLayer.
On the workstation node enter cd ~/chef-repo.
Next, we will bootstrap the new node using knife. This includes telling it which recipe to assign to the node, the attributes needed for changing the default passwords, and passing the user and password of the operating system. The command will look like:
knife bootstrap --run-list "recipe[sendmail],recipe[drupal]" --json-attributes '{"drupal": {"version": "7.26", "db": {"password": "mydbpassword"},"site": {"admin": "zAdmin", "pass": "mypassword", "name": "DemoChefSite"}}}' --ssh-user root --ssh-password mypassword 9.23.82.188So, what does this command do?
First, we tell knife to bootstrap the node with IP 9.23.82.188 and to access that node using the credentials specified by ssh-user/ssh-password. As part of the initial configuration, we also tell Chef to install the sendmail and Drupal recipes, and to override some of the default parameters for Drupal (for example, which version to use and which users/passwords to set).
Once this script is complete your node should be configured with Drupal. You may log in to the UI with the Drupal admin and password you specified on the command line, using the default http port http://9.23.82.188.
In the next installment, I will describe how to automate the deployment process. This will give you an end-to-end script for provisioning and configuring an instance.
-Wissam