My first forray into Ansible

Learning Ansible has been on my to-do list for a very long time now but I finally found the time to learn it, play with it and even write scripts to

  • create a server on Vultr
  • configure a server based on my preferred configuration
  • deploy an Apache server and a MySQL server
  • Configure the Apache and MySQL server for WordPress
  • Restore my old WordPress install to the new WordPress install

It took Kris about 2 hours to teach me the basic and a total of 8 hours to do the rest based on looking at what Kris showed me and a ton of Google searches. The end result is that I have a base repository of steps that I’ve put into roles so that I can use it in the future.

If you’ve seen my previous posts, I tend to write a lot about how to install software that I’ve been using. I’ve often used those blog posts as a build book that is publicly posted so that I can refer to it again later on to re-build any software in the future. Ansible allows me to take this one step further – it allows me to create scripts that can automatically be runnable by anyone assuming they have the appropriate requirements that is covered by that script. In my case, my initial scripts are meant for a Ubuntu host target.

Some of the things that I learned and/or appreciated about my use of Ansible this weekend:

It’s way easier than to write Shell scripts

Granted, I’m not as familiar with shell scripts as I once was but within about 10 hours, I could easily create steps that were repeatable with a very small amount of ramp up. I can’t think of anything that is available today that is simpler. I prefer not to modify my ssh config so that the sudo user on the server does not need the sudo password to run higher level security actions. To do that you can run —ask-sudo-pass as part of the command line.

There is a huge sample base of scripts or roles

It’s pretty easy to find samples of ansible scripts to do exactly what you want to do and more. A lot of what I ended up doing over the weekend was to actually simplify the samples that I found

Roles is where the magic happens with Ansible

Ansible seems to be most powerful if you organize the scripts that you need to use as roles. The way I organize my installs are as following:

  • Infrastructure (Installing any vendor specific configurations for your servers)
  • OS configurations (Install any services and configurations at the OS level
  • Application Servers (Install any app servers like Apache Web Server, Java, etc)
  • Application Frameworks (Install WordPress, Ruby on Rails, etc)
  • Application Configurations (Apply any specific application configurations)

I’ll post my initial version of roles to my public Bitbucket account once I find the time to split my git repositories. All in all, it was good fun to figure out how to use Ansible for my own use.