Walkthrough: Running Chef cookbooks from the BMC Server Automation console

This topic walks you through the process of running a Chef cookbook on a target server from the BMC Server Automation (BSA) consoleThis topic includes the following sections:

Introduction

This topic is intended for system administrators.

The goal of this topic is to demonstrate how to use the BSA console to deploy a Chef cookbook (and pre-requisites) to a server currently being managed by BSA.

What does this walkthrough show?

This walkthrough includes two scenarios:

  • In scenario 1, the administrator wants to deploy a Chef cookbook that installs Java and creates a license file to a development server in the environment. However, the target server does not have the Chef Agent installed. So, the administrator wants to install the Chef Solo Agent and run the cookbook. 
  • In the second scenario, the target server already has the Chef-Solo Agent installed, so the administrator just wants to run the Chef cookbook that installs Java and creates a license file. 

What do I need to do before I get started?

  • For these two walkthroughs, we have logged on as BLAdmin, the default superuser for BSA. 
  • Ensure the necessary Chef files are available, including all databags, environments and other dependencies, such as Ruby. Add the files to the Depot in the Depot > Chef > Chef Content > Chef Accessories folder. For more information about Chef-solo, see the Chef online technical documentation.
  • You also have to ensure that you have met the requirements described in Overview and requirements for the Chef integration.

Scenario 1: Install Chef-solo and run a cookbook on a target

In this scenario, the system administrator wants to execute a cookbook on a development machine that installs Java on the target and creates a webserver license file as well. But, the admin also needs to install the Chef-Solo Agent on the target server as well, as it has not been previously installed and is required to run the cookbook.

To do that, the admin uses the BSA console to bundle the Chef-Solo Agent install files and import them into the Depot, and then to import the Chef cookbook, as well as any dependent files for the cookbook.

 StepExample screen
1

In the BSA console, select Actions > Chef > Create Chef Agent Bundle

2

Select the location of Chef Solo Agent installer file on the Select Chef Agent Installable Sources dialog box and click OK to import the Chef Solo installer.

The Create Chef Agent Bundle General dialog box is displayed.

3
  1. On the Create Chef Agent Bundle General dialog box, verify the location of the Chef Agent installer, and specify the version of the Chef Agent. 
  2. Specify the the location of the Ruby installer, as well as any dependent installers.
  3. Specify the OS details of the target server.
  4. Click Finish.
4

Completing this wizard automatically executes the Chef Packager Script Job NSH script job, as you can see in the Tasks in progress pane.

This job creates several artifacts in the console folders:

  • A Depot folder named Agent under the Chef > ChefContent Depot folder. This folder has all installers that you just uploaded as well as a BLPackage for the Chef-solo Agent and Ruby installables.
  • A Jobs folder named Agent under the Chef > ChefContent Job folder. This folder has the deploy job for deploying the Chef-Solo Agent and Ruby installers.

5

Import the JSON files for Chef Data Bags, Role and Environments to the corresponding Depot folders under Chef > ChefContent > ChefAccessories.

To add a file to a folder:

  1. Right-click the depot folder where you want to add a file. 
  2. From the pop-up menu, select New > File.
  3. Provide information for the file by completing the panels in the wizard.  
  4. Click Finish to close the wizard and save your changes.
6

Next, we need to add the cookbook to the Depot.

Select Actions > Chef > Create Cookbook Bundle.

7

Next, you need to import the Chef cookbook, roles, environment, and databags. 

  1. Select a cookbook that was previously created or downloaded. In this example, we select a Chef Cookbook that includes two recipes: on that installs Java and one that creates a license file on target.
  2. Click OK.

Note: If desired, you can import an individual recipe instead of the whole cookbook.


8
  1. On the Create Chef CookBook Bundle dialog box, select the JSON file for the node (node_web.json). The JSON file contains the run list and attributes for the cookbook.
  2. Specify a data bag name in the Data Bag Name field.. 
  3. Click the Add button () and select one or more JSON files for each of the following to import them into the Depot:
    1. Data Bags
    2. Roles
    3. Environments 
  4. Click Finish.

9

Completing this wizard executes the Chef Cookbook2BlPkgScript Job, as shown in the Tasks in progress bar to the right.

This job creates several artifacts in the console folders:

  • A Depot folder named CookBooks under the Chef > ChefContent folder. This folder has a sub folder with the name of the cookbook you imported. The sub folder contains the node.json file, .the tar.gz file, and the BLPackage that was created for the cookbook.
  • Jobs folder named CookBooks under the Chef > ChefContent folder. This folder has a sub folder with the name of the cookbook you imported. The sub folder contains a Deploy Job for the cookbook. The sub-folder also has a Batch Job which contains the Deploy Job for both the Chef-Solo Agent and Chef Cookbook.

Depot folder

Job folder

10

The next step is to execute the batch job (shown in the example to the right) against the target on which you want to install Chef Solo and run the Chef Cookbook.

  1. Right-click the job and select Execute against.
  2. On the Targets panel, select the server on which to run the cook book.
  3. Select OK.

The Batch Job copies and installs Chef-solo and Ruby on the target if the target does not have them already installed. It then deploys the cookbooks to the target and executes them through the Chef-solo Agent. You can evaluate the results of the Batch Job run and the Deploy Job run to see the status of the cookbook deployment.

11

Verify that the cookbook was successfully executed on the target.

For example, using the command line in the figure to the right indicates that both Java and the license file have been installed.

Scenario 2: Executing a Chef cookbook on a target

In this scenario, the Chef-Solo agent is already installed on the target server, so we just want to run the cookbook to install java and create the license file.

 StepExample screen
1

Import the JSON files for Chef Data Bags, Role and Environments to the corresponding Depot folders under Chef > ChefContent > ChefAccessories.

To add a file to a folder:

  1. Right-click the depot folder where you want to add a file. 
  2. From the pop-up menu, select New > File.
  3. Provide information for the file by completing the panels in the wizard.  
  4. Click Finish to close the wizard and save your changes.
2

Next, we need to add the cookbook to the Depot.

Select Actions > Chef > Create Cookbook Bundle.

3

Next, you need to import the Chef cookbook, roles, environment, and databags. 

  1. Select a cookbook that was previously created or downloaded. In this example, we select a Chef Cookbook that includes two recipes: on that installs Java and one that creates a license file on target.
  2. Click OK.

Note: If desired, you can import an individual recipe instead of the whole cookbook.


4
  1. On the Create Chef CookBook Bundle dialog box, select the JSON file for the node (node_web.json). The JSON file contains the run list and attributes for the cookbook.
  2. Specify a data bag name in the Data Bag Name field.. 
  3. Click the Add button () and select one or more JSON files for each of the following to import them into the Depot:
    1. Data Bags
    2. Roles
    3. Environments 
  4. Click Finish.

Completing this wizard executes the Chef Cookbook2BlPkgScript Job, as shown in the Tasks in progress bar to the right.

This job creates several artifacts in the console folders:

  • A Depot folder named CookBooks under the Chef > ChefContent folder. This folder has a sub folder with the name of the cookbook you imported. The sub folder contains the node.json file, .the tar.gz file, and the BLPackage that was created for the cookbook.
  • Jobs folder named CookBooks under the Chef > ChefContent folder. This folder has a sub folder with the name of the cookbook you imported. The sub folder contains a Deploy Job for the cookbook. The sub-folder also has a Batch Job which contains the Deploy Job for both the Chef-Solo Agent and Chef Cookbook.

Depot folder

Job folder

6

Run the Deploy Job created in the previous step to execute the Chef cookbook on the target development server.

This job deploys the cookbook to the target and executes it through the Chef-solo Agent. You can evaluate the results of the Deploy Job run to see the status of the cookbook deployment.

7Verify that Java was installed and the license file created on the target.

Wrapping it up

Congratulations! You have now used the out of the box Chef integration to run a Chef cookbook on a target server from the BSA console.

Where to go from here

If you run into issues, see Troubleshooting issues with the Chef integration.

You can also execute Chef scripts from the command line.

Was this page helpful? Yes No Submitting... Thank you

Comments