Chapter 7. Deploy an Instance Using a Heat Template

In the previous section we deployed a single virtual machine instance to ensure basic operation of the Red Hat OpenStack Platform 10 cloud environment. In this section we will expand on this configuration by deploying a virtual machine instance using a heat template, registering the machine using Red Hat Subscription Manager, and then installing a Sensu monitoring client on the virtual machine instance.  
Using a heat stack to create the virtual machine instance allows the user to create an instance and install software with a single command. The heat template used in this example can be found in Appendix B under the section titled "Heat Template for Instance Deployment"

In this example the heat template will be launched from the Red Hat OpenStack Platform director by the stack user. The template has been stored in a directory /home/user/stack/templates/mytemplates/inst/inst.yaml. Additionally, source the environment file (keystonerc_hpdemo) to ensure the correct OpenStack username, password, and tenant environment variables are set.

$ source keystonerc_hpedemo

To launch the heat template execute the following command:

$ openstack stack create -t templates/mytemplates/inst/inst.yaml --parameters "rhn_user=<rhnUserName>;rhn_password=<rhnPassword>;rhn_pool=<rhnPoolID>;rhn_hostname=<instanceHostName>" <stack name>

In the command line example above, substitue the command line --parameter option variables with parameters that match your environment.

Use the command _openstack stack list to view stack that was created for the instance.

Execute nova list to view list virtual machine instances and obtain the virtual machine instance UUID for the virtul machine created by the heat stack template.

The command openstack server show <instance UUID> will provide details about the newly deployed instance.

$ openstack server show 6a4ca385-a901-48bb-8a51-eb301108ce13

The instance can be accessed by using ssh -i, hpeuserkp.pem, the cloud-user account, and the Floating IP address to log into the instance. This assumes the keypair (hpeuserkp) has been downloaded as hpeuserkp.pem in the current working directory.

$ ssh -i hpeuserkp.pem cloud-user@10.19.20.184

To delete the stack and the virtual machine instance use the command openstack stack delete <stack name>.

As described earlier, Red Hat OpenStack Platform 10 services are monitored by a Sensu server using Sensu subscriptions and checks. This monitoring functionality can be extended to virtual machine instances by adding a Sensu client to the virtual machine instances during deployment. The virtual machine instances can be registered with the existing Sensu server, or an additional Sensu server can be installed to provide a separate monitoring domain for the deployed services. Both the virtual machine instance monitoring and OpenStack service monitoring can be viewed from a single instance of Uchiwa. Figure 5, shown below, illustrates the virtual machine instances registered with Sensu and displayed in the Uchiwa dashboard after being deployed using the heat template inst.yaml.

Sensu Monitoring of RHOSP Instances

Figure 5: Sensu Monitoring of Red Hat OpenStack Platform Instances

To accomplish this we will include the installation of the Sensu client, erlang, and rabbitmq in the heat template that is used to deploy the instance.
The heat template will also create the Sensu client files necessary to register the instance with the existing Sensu server.
Below is an excerpt from the heat template that is used to create the instance.

           echo '{
              "client": {
                "name": "localhost",
                "address": "127.0.0.1",
                "subscriptions": [
                  "test"
                ]
              }
            }' | tee /etc/sensu/conf.d/client.json
            echo '{
             "rabbitmq": {
               "port": 5672,
               "host": "10.19.20.200",
               "user": "sensu",
               "password": "sensu",
               "vhost": "/sensu",
               "reconnect_on_error": false,
               "prefetch": 1
             }
           }' | tee /etc/sensu/conf.d/rabbitmq.json
             echo  '{
             "transport": {
               "name": "rabbitmq",
               "reconnect_on_error": true
             }
           }' | tee /etc/sensu/conf.d/transport.json

An example of the complete heat template can be found in Appendix B of this document.

The next step is to apply the instance hostname and IP Address to the Sensu client.json configuration file. A simple ansible script will be used to replace the "name: "localhost" and "address":"127.0.0.1" values in /etc/sensu/conf.d/client.json file. This script will also start the sensu-client service on the instance. The ansible script can be pulled down from a git repository using the heat template.

---
- hosts: all
  tasks:
     - name: replace ip
       replace:
         dest: /etc/sensu/conf.d/client.json
         regexp: "127.0.0.1"
         replace: "{{ ansible_eth0.ipv4.address }}"
         backup: no
     - name: replace hostname
       replace:
         dest: /etc/sensu/conf.d/client.json
         regexp: "localhost"
         replace: "{{ ansible_fqdn }}"
         backup: no
     - name: start Sensu Client
       shell: systemctl start sensu-client

The above script will register the Sensu client running on the instance with a Sensu server that is listening on 10.19.20.200:5672. The virtual machine instance should now appear in the Uchiwa dashboard. Additional application and operating system checks can be added to the Sensu server and subscribed to by the Sensu client running on the virtual machine instance.