Introduction: Deploying Drupal on SoftLayer with Chef - Part 2

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.

Set up the Development Machine

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.

Set up the Chef Server

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 <id> --passwords 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:

  • Select the Chef server tab.
  • Select the Operating System (Ubuntu in our example).
  • Select the Operating System version and the platform (12.04 and x86_64).
  • Select the Chef server version to download (11.0.10).
  • The package will display as an option; right click and copy the URL link.

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

Set up the Chef Workstation

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:

  1. Where should I put the config file? ~/chef-repo/.chef/knife.rb
  2. Please enter the Chef server URL: https://chef-server-demo.softlayer.com:443;
  3. Please enter a name for the new user: wsadmin
  4. Please enter the existing admin name: admin
  5. Please enter the location of the existing admin's private key: ~/chef-repo/.chef/admin.pem
  6. Please enter the validation clientname: chef-validator
  7. Please enter the location of the validation key: ~/chef-repo/.chef/chef-validator.pem
  8. Please enter the path to a Chef repository: ~/chef-repo
  9. Then enter a user name for the new user: wsadmin

Verify 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:

  • Edit the file vim ~/chef-repo/cookbooks/drupal/templates/default/grants.sql.erb and change the % symbol to localhost such as:
    GRANT ALL ON <%= @database %>.* TO '<%= @user %>'@'localhost' IDENTIFIED BY '<%= @password %>';
  • Edit the file 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

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.

  • Log in to the chef-drupal-demo machine and follow the same steps for setting the FQDN on the system.
  • Add an entry in /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.188

So, 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

Was this helpful?