The chat example

A few months ago, I needed to set up a demo to show automation working—however, I needed to be able to show the demo on my laptop or phone, which meant that I couldn't assume I had access to the command line.

The demo I came up with ended up using Slack and a few other tools that we haven't covered in this book, namely Hubot and Jenkins; before I go into any details, let's quickly have a look at the output of the demo running:

As you can see from the preceding output, I asked the following in a Slack channel:

@bot give me a linux server

This then triggered an Ansible playbook run, which launched an instance in AWS and returned information on the instance once the playbook had confirmed that the server was available on the network. I also configured it to remove all running instances by asking the following:

@bot terminate all servers

As you can see, this runs another playbook, and this time, returns an animated GIF once the instance has been removed:

So, what did I use for this? As already mentioned, for a start, I used Hubot. Hubot is an open source extendable chatbot developed by GitHub. It was configured using the hubot-slack plugin in my Slack channel, and it listened out for any commands it was given. 

I used the hubot-alias plugin to define an alias that translated @bot give me a linux server into build awslaunch OS=linux; this used the hubot-yardmaster plugin to trigger to a build in my Jenkins installation.

Jenkins is an open source automation server, used mostly for continuous integration and also continuous delivery—it too has a plugin architecture. Using the Jenkins Ansible plugin and also the Jenkins Git plugin, I was able to pull the playbook and roles used to launch the AWS instance to my Jenkins server and then have Jenkins run the playbook for me—the playbook itself wasn't too dissimilar from the playbook we worked through in Chapter 9Building Out a Cloud Network, and Chapter 10, Highly Available Cloud Deployments.

The playbook had a little logic built into it that limited the number of instances that could be launched, randomized the name of the instance that it was launching, and also displayed a random GIF from a list of several options—all of this information, along with details of the instance and the AMI, were all passed to the user via the Ansible Slack module to give the impression that the playbook was actually doing more than it was.

In the two preceding examples, the bot user is Hubot, and Jenkins is actually the feedback from the playbook run.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.202.187