Skip to main content

Programming, Day 30, Ansible

I finally got tired of rebuilding my servers from scratch everytime.
It hadn’t troubled me enough to do something about it, until recently.
I got myself a pc to do linux development on and I keep nuking the os and reinstalling.

Rebuilding it over and over was exciting in the beginning and then it sudddenly began to grate on my nerves.
So I decided to put in my twenty hours after my break and learn Ansible.

I know Ansible!


What it is at its heart, is a recording & playback engine for setting up computers.
You record the steps you usually do, in a text file, using a language called YAML on your mac or pc or what have you.
And then you playback those actions on your server or target pc.
Ansible gives you primitives, the basic building blocks, called modules to do just about anything you wish.

In my case,

  • I setup a barebones server running Bionic Beaver and configured it for ssh access
  • Everything from then on, was controlled by the YAML playbook I was building step by step
  • I updated the machine
  • I configured three users
  • I setup UFW & Fail2Ban
  • NGINX was next
  • I configured my 4 little play subdomains
  • And finally configured Letsencrypt and enabled SSL

And that’s about all I wanted from my basic machine so far.
Running the script start to finish takes about 30 mins and I have a machine ready to go!
Doing all that by hand is fraught with errors and takes me nearly half a day.

Every other task I need done now, I’ll start doing via Ansible.

There’s obviously lots more to learn. The playbook (my recording) started from nothing and has now grown to an unwieldy 200 odd lines.
I can hive them off into other files and call them seperately.
I can optimize what I’ve written, and make it portable, so that I can setup any server I wish, not just mine.

But all that is for later.

I did this, so I could have a machine to trash and rebuild quickly.
Now that I have one, Python, here I come.

P.S.
It also gave me a small sense of how coding actually works.
It was slow steady progress.
Building a bit, testing, iterating, tinkering and playing.
And at the end of the day, I have something that I can call my own, something I built and something that makes my work easier.
By Jove, this is going to be fun!