Automating tasks with Ansible on Bright Cluster Manager head nodes and software images.

    

Ansible is a simple, agentless IT automation tool that anyone can use. In this blog post, we will look at automating head node and software image tasks using Ansible.

We start by installing the Ansible packages as per the Ansible documentation on their website: https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html

This could be onto the Bright headnode itself, or a management system such as your desktop, laptop or virtual machine which has connectivity to the head node via secure shell (SSH). As Ansible makes use of secure shell (SSH) to manage and automate tasks, a prerequisite here is to configure passwordless authentication using public keys between the management system and the head node. Configuring this falls outside the scope of this article; however, there are many examples available online.

Once passwordless authentication is configured, we may start configuring Ansible. In the Ansible configuration directory, typically /etc/ansible, we start by setting up the hosts file (/etc/ansible/hosts).

An example of this might be:

 [bright-headnode]

bright82-headnode

In the above example, we have created a group called “bright-headnode” and added bright82-headnode as a host. In this case, the hostname of the Bright head node is “bright82-headnode”. Next, we will need to build a playbook to run some tasks. In this example, we will write tasks to upgrade the packages on the head node and in the default-image software image using the yum package manager module of Ansible. The playbook file is written in yaml format and is stored in /etc/ansible/playbook.yml.
---

- hosts: bright82-headnode

  tasks:

  - name: upgrade all packages on headnode

            yum:

            name: '*'

            state: latest

  - name: upgrade all packages on default-image

            yum:

            name: '*'

            state: latest

            installroot: /cm/images/default-image

Finally, we will get Ansible to execute the requested tasks in the playbook.

# ansible-playbook /etc/ansible/playbook.yaml

The output might look something like this:

PLAY [bright82-headnode] ********************************************************* 

TASK [Gathering Facts] *********************************************************

ok: [bright82-headnode]

TASK [upgrade all packages on headnode] ****************************************

changed: [bright82-headnode] 

TASK [upgrade all packages on default-image] ***********************************

changed: [bright82-headnode]

PLAY RECAP *********************************************************************

bright82-centos           : ok=6  changed=2      unreachable=0            failed=0  

 

Based on the above output, we have successfully upgraded the head node and default-image software image with the latest packages. What other tasks could we automate? If we have a compute node called “node001” which is our development node, we could add a task to reboot this node each time we run our Ansible playbook to test out the software updates. In our playbook yaml file, we would add the following:

  - name: Reboot development node001 to test software changes

            shell: cmsh -c "device; reboot -n node001"

Another option might be to perform an image update on node001 using Bright.

  - name: Update image on development node001 to test software changes

            shell: cmsh -c "device; imageupdate -n node001 -w"

 

As you can see, the above example provides a powerful way to automate tasks using the bash shell and the Bright command line cmsh tool. While the above examples are quite simple, they can be used to build powerful automation processes to streamline the day to day functions of your cluster.