Quick tests of WebSphere apps, easily done in the cloud

By Hans Moen

Quick tests of WebSphere apps, easily done in the cloud

There are several cases where it is useful to be able to stand up additional WebSphere capacity for a limited time period, without needing to worry about data center server capacity and software licenses. Typical examples include batch type workloads, test of new code at infrequent intervals, maybe as part of an overall application modernization strategy.

What is Ansible?

Ansible is a popular open-source agentless automation engine that automates software provisioning, configuration management, and application deployment.

WebSphere Application Server in Bluemix is perfect for these type of use cases, being able to provision a dedicated WebSphere environment charged by the hour. When you don’t need the environment you can shut it down, hence saving cost. More information in Bluemix Documentation Pages

However, as the mantra goes, if you do something more than once – automate it.

This is why we created the wascloud Ansible Module. This module allows you to manage WebSphere Cloud Instances in similar fashion to the way you would manage AWS, OpenStack and SoftLayer VMs through the corresponding modules.

By using the dynamic inventory functions in Ansible you can create instances, configure websphere and load WebSphere applications as part of a single playbook.

Usage

The module takes the following input

region: Bluemix region, one of ng (us south), eu-gb (london), au-syd (sydney) org: Your bluemix organisation space: The bluemix space to provision in apikey: Your bluemix api key

name: Name of WebSphere on Cloud instance to create or delete state: One of present – Creates a new instance if no instance by that name exists. If it exists the resource information for the instance is returned. absent – Deletes an instance if it exists. latest / reloaded – Creates an instance if no instance by that name exists, if instance already exists old instance is deleted. Can be used to ensure latest fixpacks and os patches are applied, and to re-set configurations.

type: Can be one of LibertyCollective, LibertyCore, LibertyNDServer, WASBase, WASCell or WASNDServer size: T-Shirt size for the application server(s) as supported by WAS Broker. Currently supported: s, m, l, xl, xxl wait: whether to wait until instance fully provisioned before continuing the playbook. If the playbook includes tasks to be performed on the newly created instance this needs to be set to true

WASCell and LibertyCollective has these additional parameters: controller_size: T-Shirt size of the controller VM. Currently supported: s, m, l, xl, xxl app_vms: How many application server VMs to create.

For WASBase, WASCell and WASNDServer: software_level: Which software level of WAS to deploy. Currently available 8.5.5 and 9.0.0. Defaults to 9.0.0 if not specified.

Module return

The module returns a number of useful variables that you can capture with the ansible register method. If the VM details of the instance is available, all the details from the WASBroker API Instance Resouce is passed into the resources list.

Importantly you will see that the wasAdminUser and the randomly generated wasAdminPassword is passed in here, so you can use it for further configuration automation

table

Pre-requisites

To work with the WAS Broker you must have a Bluemix API key. Information on getting the API key from the Bluemix IAM Documentation pages This allows you to create, delete and get information about WAS Instances

To work on the websphere instance you will need an OpenVPN connection to WebSphere region. Information on setting up the OpenVPN connection from the Bluemix ApplicationServices Documentation pages

The module has been submitted for inclusion in Ansible 2.5, but in the meantime the code needs to be placed in one of the defined Ansible library paths, so Ansible can find it. Generally it should suffice to place it in ./library along the playbook. More about this approach as well as other approaches on the Ansible Documentation pages

And of course, you need a working version of Ansible installed.

Example usage

There are plenty of examples in the github repository (link to follow)

<br>
---<br>
- hosts: localhost<br>
  connection: local<br>
  gather_facts: False<br>
  vars_files:<br>
  - ../bluemix-vars.yaml<p></p>
<p>&amp;amp;amp;amp;amp;amp;amp;amp;nbsp; tasks: </p>
<p>&amp;amp;amp;amp;amp;amp;amp;amp;nbsp; - name: create instance<br>
    wascloud_instance:<br>
    state: latest<br>
    name: "{{ was_instance_name }}"<br>
    instance_type: WASBase<br>
    size: s<br>
    region: "{{ region }}"<br>
    org: "{{ org }}"<br>
    space: "{{ space }}"<br>
    apikey: "{{ apikey }}"<br>
    wait: True<br>
    register: was_instance </p>
<p> - name: Add new instance to host group<br>
    add_host:<br>
      hostname: "{{ item.osHostname }}"<br>
      groupname: launched<br>
      ansible_user: "{{ item.osAdminUser }}"<br>
      ansible_ssh_pass: "{{ item.osAdminPassword }}"<br>
      ansible_ssh_common_args: "-o StrictHostKeyChecking=no -o PreferredAuthentications=password -o PubkeyAuthentication=no"<br>
      wasadmin: "{{ item.wasAdminUser }}"<br>
      wasadminpass: "{{ item.wasAdminPass }}"<br>
    with_items: "{{ was_instance.resources }}"<br>
- name: Wait for ssh to become available<br>
  wait_for:<br>
    host: "{{ item.osHostname }}"<br>
    port: 22<br>
    sleep: 2<br>
    timeout: 300<br>
    state: started<br>
  with_items: "{{ was_instance.resources }}"</p>
<p>- hosts: launched<br>
  gather_facts: True<br>
  vars_files:<br>
  - db-vars.yaml<br>
  roles:<br>
  - my_important_role<br>
  - my_important_tests<br>
</p>

Now what?

If you’re looking at WebSphere Application Modernization, and you haven’t read it yet, you should head over and read Rick Osowskis blog on WebSphere on the Cloud: Application Modernization

To get your hands dirty, head over to the ansible-wascloud github repo, look at some of the examples there and try adapt one to fit your requirements.

Be the first to hear about news, product updates, and innovation from IBM Cloud