Getting started with the Chef cookbooks for Liberty profile

A quick guide to getting up and running using the Chef cookbooks for Liberty profile. Set up a virtual machine running a Liberty profile server with a sample application deployed.

There have been several releases of the Chef cookbooks for Liberty profile. Here is a quick guide to getting up and running using those cookbooks. The cookbooks set up a virtual machine running a Liberty profile server with a sample application deployed.

Opscode Chef is a popular DevOps solution for automating infrastructure configuration. Using Chef, you configure from the operating system up; applying system updates, modifying configuration files, restarting any necessary system services, applying and configuring middleware and applications.

You do this through Chef cookbooks, which contain recipes, templates, and attributes. It is these which control the infrastructure automation. You can write your own cookbook or take advantage of the community-contributed cookbooks published on the Opscode community. Cookbooks for many popular software packages are available including ones for IBM’s WebSphere Liberty profile.

Set up the Chef environment on your workstation

The steps to set up your Chef environment are described in the Chef QuickStart guide, which to summarize says:

Accept all the default options when installing those products.

If you use Windows, you also need to set your editor, for example, to use WordPad. At a command prompt enter: setx EDITOR "\%ProgramFiles%\Windows NT\Accessories\wordpad.exe\"

Create a Chef account and download the Chef StarterKit

  1. Create yourself an Enterprise Chef account.
  2. Open your Chef organizations page and select your organization.
  3. Click download StarterKit and unzip the downloaded package to your local file system. This creates a directory named chef-repo.

Set up git, and install the cookbooks and their dependencies

  1. Open a Git Bash prompt at your StarterKit chef-repo directory.
  2. Initialize Git with the following commands:
    $ git init .
    $ git add .
    $ git commit -m "Initial commit"
  3. Install the Chef cookbooks to your local chef-repo directory. This also automatically installs all the dependent cookbooks such as the wlp and java cookbooks:
    $ knife cookbook site install apt
    $ knife cookbook site install application_wlp

Create a recipe to deploy the JSPExample application

  1. In your chef-repo directory, go to cookbooks\starter\recipes.
  2. Create a file named JSPExamples.rb with the following contents:
    application "JSPExamples" do
    
      repository "http://central.maven.org/maven2/org/apache/geronimo/samples/jsp-examples-war/3.0-M1/jsp-examples-war-3.0-M1.war"
      path "/usr/local/JSPExamples"
      scm_provider Chef::Provider::RemoteFile::Deploy
      owner "wlp"
      group "wlp-admin"
    
      wlp_application do
        server_name "JSPExamples"
        features [ "jsp-2.2", "servlet-3.0" ]
      end
    
    end
    
    # start server if it is not running already
    wlp_server "JSPExamples" do
      action :start
    end
  3. In your chef-repo directory, edit the file cookbooks\starter\metadata.rb and, at the bottom of the file, add the line:
    depends "application_wlp"
  4. At the Git Bash prompt again enter:
    $ knife cookbook upload -all

Configure and bring up VirtualBox using Vagrant

  1. Edit the Vagrantfile configuration file in the chef-repo directory and change 8080 to 9080 on the line:
    config.vm.network :forwarded_port, guest: 8080, host: 9090
  2. To bring up your virtual machine, at a Git Bash prompt in your chef-repo directory enter:
    $ vagrant up

    That will take a good few minutes the first time as it downloads the vm image.

Bootstrap the VM so it can poll the Chef server for configuration updates

  1. When the VM is up, configure Chef on the VM with the following command:
    $ knife bootstrap localhost  --ssh-user vagrant --ssh-password vagrant --sudo --run-list "recipe[apt]" --ssh-port 2222

    That installs the Chef client and does some configuration of the VM.

  2. Download the IBM Java and Liberty installation files (you could use non-IBM Java too but for this example we’re using an IBM one):
    • Download Java 7 from IBM developerWorks and put the file (ibm-java-i386-sdk-7.1-0.0.bin) in your chef-repo directory
    • Download the Liberty profile runtime jar and the extended content jar from IBM WASdev and put the jars in your chef-repo directory

Set your node’s configuration to configure the example application and dependencies

  1. Use the following command to update the Chef node with the attributes required to configure the Liberty cookbooks:
    $ knife node edit <yourName>-starter

    (where <yourName> is your Enterprise Chef account user ID)

    That should bring up an editor with some JSON text.

  2. In the editor, add the following text highlighted in red so that your file matches, and save the file:
    {
      "name": "<yourName>-starter",
      "chef_environment": "_default",
      "normal": {
        "wlp": {
          "archive": {
            "accept_license": "true",
            "base_url": "file:///vagrant/"
          }
        },
        "java": {
          "install_flavor": "ibm",
          "ibm": {
            "url": "file:///vagrant/ibm-java-i386-sdk-7.1-0.0.bin",
            "accept_ibm_download_terms": "true"
          }
        }
      },
      "run_list": [
        "recipe[apt]",  
        "recipe[starter::JSPExamples]"
      ]
    }

    This directs Chef to accept the Liberty profile and IBM Java licenses at installation time, on your behalf. They are the same licenses you accepted when you downloaded them from ibm.com.

  3. Go into your VM with the following command:
    $ vagrant ssh
  4. At the Git Bash prompt enter the following command to manually run the chef-client:
    ~$ sudo chef-client

    Usually, chef-client would run as a cron job, polling the Chef server for updates to its JSON-based configuration.

    It will take a while to install IBM Java and Liberty profile, then create and start a Liberty server with the JSPExamples application deployed.

That’s it. The Liberty server should be up and running with the sample application available. In a web browser, go to http://localhost:9090/JSPExamples/ and you should see the application web page.

We’d love your feedback. Post your questions to the WASdev forum or on Stack Overflow, or open issues in our GitHub repositories: WASdev/ci.chef.wlp and WASdev/ci.chef.wlp.application.

To learn more about and experiment with Chef take a look at the Opscode #learnchef page.