Posted by & filed under Ansible, Programming & Sysadmin.

This is going to be a series of posts about building a web interface to use with Ansible to run commands on remote servers for system administration. This is a learning exercise, not a fully developed application that you can drop on your server.

It will be written in python, using a simple https server. The interface will be a one-page jquery powered app that will run an Ansible command against a list of servers.

The simple https server will be based on this post.

Ansible commands look like this:

ansible $HOSTNAME -m command -a "df -h"

That is a simple ansible command that says to use the “command” module to run “df -h” on host $HOSTNAME.

Requirements: You should have ansible installed and understand basic ansible commands before continuing, otherwise this won’t make much sense to you. You should also have a basic understanding of a simple web server, file paths vs url paths, and some basic python. You might also want to consider the security of this, since there isn’t much security built in. I run it in an encrypted VM that is only accessible from my workstation.

Why do this?

System administration often consists of typing long complex commands. Ansible commands can also be long and complex, but ansible allows you to run commands on multiple systems at the same time. It is a big time saver. Creating a web interface, allows a system administrator to select an ansible module with a checkbox, select hosts to run commands on with checkboxes, and to re-use ansible commands and commonly system administration commands in a time-saving way.

So, instead of typing this to add user $USERNAME to the wheel group on three systems:

ansible $HOST1:$HOST2:$HOST3 -m user -a "name=$USERNAME state=present groups=wheel append=yes" --su

Using a web interface, you could:

  1. Click to choose the “user” module to manage users.
  2. Check the boxes for the three hosts to run ansible agains.
  3. Enter the username in the Username box.
  4. Enter “wheel” in the Groups box, and check “append”.
  5. Click submit
  6. Ansible runs command above and the results are displayed.