Introduction

This is a step-by-step example of how to use Chef to deploy a basic LAMP server stack on a NeCTAR virtual.  We first launch the new virtual, and bootstrap with Chef-DK, and then use the "lamp" cookbook from "nectar-cookbooks" to install the stack and do some basic configuration.

(I will assume that you are generally familiar with the NeCTAR Dashboard, and just provide a "checklist" of the necessary steps in the launch process.)

Launching and bootstrapping Chef

Start by logging into the NeCTAR research cloud, and going to the NeCTAR Dashboard.

  1. Select the Project (aka Tenant) you want to launch in.
  2. Go to the Access & Security panel and create and/or configure an access group which allows TCP access for SSH (port 25), HTTP (port 80) and HTTPS (port 443).
  3. Go to the Instances panel, and click "Launch Instance"
  4. Enter / select the normal Instance launch details: the instance name, the instance flavour, the availability zone, the NeCTAR image to start from, a key-pair (for SSH access), and the access group.
  5. Copy the following into the Post-Creation > Customization script box:
    #!/bin/sh
    wget -O - https://github.com/nectar-cookbooks/chef-solo-repo/raw/master/scripts/bootstrap-nectar-chefdk.sh \
    | /bin/sh > /root/bootstrap.out 2>&1
  6. Click "Launch"

Once the instance has launched, connect to it via SSH (using "ubuntu", "ec2-user" or whatever as the account name), and use something like "sudo fail -f /root/bootstrap.out" to monitor the Chef bootstrap progress.

When the bootstrap has finished, you should have a working Chef installation with Berkshelf and some other Chef development tools.  In addition, "/var/chef-solo/chef-solo-repo" should be populated with a Berksfile for the nectar-cookbooks project, a "mynode.json" file where you can put your node configuration information.

Installing the LAMP stack.

First, take a look at the documentation for the "lamp" cookbook: https://github.com/nectar-cookbooks/lamp.  This explains (briefly) what the recipes do, and the "attributes" you can use to configure them.

Now change directory to your "/var/chef-solo/chef-solo-repo" directory and take a look at the "mynode.json" file.  If you cave just bootstrapped Chef, it will look like this:

{
  "name": "sample-chefsolo",
  "chef_environment": "_default",
  "setup": {
     "set_fqdn": "*"
  },
  "run_list": [
    "recipe[setup::default]"
  ]
}

The name attribute is conventionally the name of your configuration, and the "chef_environment" attribute is boiler-plate.  Following that, the "setup" attribute is specifying the recipe attributes for the "setup" cookbook - in this case the "fqdn"  attribute.  Finally. the "run_list" attribute gives the sequence of recipes to be run - in this case "setup::default".

In summary, the "mynode.json" file currently tells Chef to run the "default" recipe from the "setup" cookbook, and provides an attribute for that recipe.  (I recommend that you read the documentation here: https://github.com/nectar-cookbooks/setup.)

To tell Chef to install the LAMP stack, we will add the "lamp::default" recipe (for Apache with PHP) and the "lamp::database" recipe (for MySQL) to the run_list.  The latter recipe requires us to provide a password for the database "root" account, so we will do this using an attribute.  The end result looks like this:

{
  "name": "lamp-server",
  "chef_environment": "_default",
  "setup": {
     "set_fqdn": "*"
  },
"lamp": {
"database": {
"root_password": "secret"
}
},
 "run_list": [ "recipe[setup::default]",
"recipe[lamp::default]",
"recipe[lamp::database]"
] }

All that remains to do now it to run "chef-solo" to do the installation, as follows

$ sudo chef-solo -j mynode.json -c solo/solo.rb

This will install the necessary LAMP packages using your system's package manager, and then do some basic configuration of the Apache and MySQL services.

This may take a little time ...

When it is finished you should have a bare Apache HTTP server that is listening for requests from the outside on port 80.