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

There have been several releases of the Chef cookbooks for WebSphere Liberty. Here is a quick guide to getting up and running using those cookbooks. The cookbooks set up a virtual machine running a Liberty 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.

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.

Chef needs to know your preferred editor. If you use Windows and WordPad enter the following at a command prompt:

setx EDITOR ""%ProgramFiles%Windows NTAccessorieswordpad.exe""

The next time you start a command prompt EDITOR will be set appropriately.

If you use Linux and vi enter the following on the command line:

export EDITOR=vi

Or put the following line in the .chef/knife.rb file in your chef-repo directory:


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 cookbooksstarterrecipes.
  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 node[:wlp][:user]
      group node[:wlp][:group]
      wlp_application do
        server_name "JSPExamples"
        features [ "jsp-2.2", "servlet-3.0" ]
    # start server if it is not running already
    wlp_server "JSPExamples" do
      action :start
  3. In your chef-repo directory, edit the file cookbooksstartermetadata.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 SE Version 7 for the 32-bit x86 platform from IBM developerWorks and put the file (ibm-java-i386-sdk-7.1-1.0.bin) in your chef-repo directory
    • Download the Liberty runtime jar and the extended content jar from IBM WASdev and put the jars in your chef-repo directory
      Note: they need to be in the chef-repo directory as Vagrant maps this to the /vagrant directory in the VM.

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-1.0.bin",
            "accept_ibm_download_terms": "true"
      "run_list": [

    This directs Chef to accept the Liberty 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 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, 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.

8 comments on"Getting started with the Chef cookbooks for Liberty"

  1. Hello,
    I tried to download cookbook and getting following error:
    > knife cookbook site install application_wlp
    Installing application_wlp to C:/opscode/chef/chef-repo/cookbooks
    Checking out the master branch.
    Pristine copy branch (chef-vendor-application_wlp) exists, switching to it.
    Downloading application_wlp from the cookbooks site at version 0.2.0 to C:/opscode/chef/chef-repo/cookbooks/application_wlp.tar.gz
    Cookbook saved: C:/opscode/chef/chef-repo/cookbooks/application_wlp.tar.gz
    Removing pre-existing version.
    Uncompressing application_wlp version 0.2.0.
    removing downloaded tarball
    15 files updated, committing changes
    ERROR: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received ‘1’
    —- Begin output of git commit -m “Import application_wlp version 0.2.0” — application_wlp —-
    STDOUT: On branch chef-vendor-application_wlp
    Changes not staged for commit:
    deleted: ../.chef/trusted_certs/vm-04da-b3ec_nam_nsroot_net.crt

    no changes added to commit
    —- End output of git commit -m “Import application_wlp version 0.2.0” — application_wlp —-
    Ran git commit -m “Import application_wlp version 0.2.0” — application_wlp returned 1

    Any idea what is wrong?

  2. QAUW_Ashwin_Radhakrishnan August 12, 2015

    Can I do configuration management for WAS ND 7/8/liberty profile using Chef ? By Configuration management what I mean is for ex: WAS ND 7, would I be able to write a recipe which will create/modify/delete JDBC data source/JMS Topic/Queue, Share library, Users modifications etc on a WAS ND 7 instance without using Jython/JACL or any other scripts. The point is update run time configurations for a product solely using Chef recipe or Chef + Docker, if its possible kindly let me know how.

  3. Jeremy Hughes February 16, 2015

    I think you’re using the wrong port when viewing from the host. The instructions above say:

    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

    so you should end up with
    config.vm.network :forwarded_port, guest: 9080, host: 9090

    Then when you hit localhost:9090 it should work.

    • Thank you. I changed the port forwarding line to config.vm.network :forwarded_port, guest: 9080, host: 9090 and I could not access localhost:9090. I tried with different ports higher than 9999 and I still cannot get port forwarding to work. I actually have another Vagrant box where I was able to forward port 3030 (dashing.io) and a non Vagrant box with port 8080 (Jenkins). They were not running when I was running the VM with WAS Liberty.

      I gave up on the port forwarding and followed every step of this blogpost. I am stuck at sudo chef-client. The only thing different in my chef-repo is the version if ibm java (ibm-java-x86_64-sdk-7.1-2.10.bin). I entered the installer’s name correctly in the node configuration (knife node edit NODE).

      The VM console has this error message when I executed sudo chef-client.

      [2015-02-19T16:30:17+00:00] WARN: Error on deploying /usr/local/JSPExamples/releases/ca2e64130c52bdca0b245a19d67c8b476b856efb4579fa1b6730412364fc6397: can’t find group for wlp-admin
      [2015-02-19T16:30:17+00:00] INFO: Removing failed deploy /usr/local/JSPExamples/releases/ca2e64130c52bdca0b245a19d67c8b476b856efb4579fa1b6730412364fc6397
      [31mError executing action `deploy` on resource ‘deploy_revision[JSPExamples]'[0m

      can’t find group for wlp-admin[0m

      The bottom of the console says:
      [2015-02-19T16:30:17+00:00] ERROR: Running exception handlers
      [2015-02-19T16:30:17+00:00] ERROR: Exception handlers complete
      [2015-02-19T16:30:17+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
      [2015-02-19T16:30:17+00:00] INFO: Sending resource update report (run-id: fd66c35e-58c5-4e2d-b857-d0a2229e182f)
      [2015-02-19T16:30:34+00:00] ERROR: deploy_revision[JSPExamples] (/var/chef/cache/cookbooks/application/providers/default.rb line 130) had an error: ArgumentError: can’t find group for wlp-admin
      [2015-02-19T16:30:34+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

      I am not familiar with chef. Did I miss something?

      • I logged into the Vagrant box where the sudo chef-client command failed and manually started the wlp server. It was running without any issues. I was even able to access it from my host from localhost:9090. There were no war files deployed in JSPExamples, but I was able to see the Websphere Liberty default page.

      • Jeremy Hughes February 20, 2015

        Hi, I see the real problem now. There’s a bug in our JSPExamples.rb file above. We were using:

        owner "wlp"
        group "wlp-admin"

        Elsewhere the default group is created which is now wlpadmin rather than wlp-admin. It would be safer to use:

        owner node[:wlp][:user]
        group node[:wlp][:group]

        I’ll get the article changed. Thanks.

        • Thank you. That worked out great. I now have a Chef provisioned, Vagrant box with Websphere Liberty installed and running.

          There is one minor change I had to make under ‘Configure and bring up VirtualBox using Vagrant’. I executed ‘vagrant init hashicorp/precise64’ to create my vagrant file. Later, when I executed ‘knife node list’, I noticed that my node was named ‘precise64’ rather than ‘-starter’. I used precise64 in the JSON text and proceeded with the rest of the steps successfully.

          Is there a different vagrant box you would recommend for this?

  4. I installed a wlp-developers-runtime- in a vagrant box. I setup port forwarding for guest: 9080 host: 8080. I deployed a simple war file to the dropins directory. I confirmed that the WAS server is up and running. I am able to view localhost:9080 on the VM, but I am not able to access from the host (localhost:8080). What am I missing?

Join The Discussion

Your email address will not be published. Required fields are marked *