Design & Technology May 12, 2016
Infrastructure as code, the benefits
Infrastructure as Code can bring the management of your infrastructure to the next level and beyond. In this blog article I will show you why you should apply it and what the benefits are.
When you are working in IT you have to manage some infrastructure sooner or later. That could be anything from the PC you use for development up to a complete server farm. Traditionally someone manually installs these servers by first installing an OS on it and logging in on the shell and run commands to install the required software. After a while it happens that you need another server in your environment. This time your colleague is going to install it. There is a big chance that this additional server is a little bit different compared to the one you installed.
Up to a few machines this is manageable, but what when you have to install some additional servers? You can do it manually again, but this is taking time, and you probably have to repeat the same steps for each server and if you do it with multiple people you start to have more differences between them. So you create a shell script that you can run on each server. This is your first step into Infrastructure as Code.
But your colleagues also need this script so you share it with them by email, but then someone makes a change and has to share that newer version with the rest. Now you have multiple version of the same script laying around. To solve that problem you can put it in a version control system. That would be your next step to Infrastructure as Code.
Then you need to add different kind of servers to your environment and you create an additional script to install those servers. And maybe one set of servers needs different configuration then others. So you need to find a solution for that. Maybe based on the hostname you can add some conditional statements in your scripts. But while your environment grows this can become a mess. And when your script fails somewhere halveway it is sometimes not possible to re-run the script without cleaning the mess it left when it failed first.
The next step would be to start using a tool that is designed for these kind of tasks. There are several of them out there. The 3 most well know ones are Puppet, Ansible and Chef. They all have their pros and cons so depending on your use case you should choose one. Once you have one of those tools setup it becomes a lot easier to manage multiple servers, from a hand full to complete datacenters.
The next step would be to introduce some principles that we know from software development, like Continuous Integration. This way you can automatically test the changes before you apply them to the actual environments you are managing.
If you do all of these things properly, it becomes a lot easier and less time consuming to manage your infrastructure. Installing a new server becomes a matter of adding it to your Puppet master or Ansible inventory, and assigning the correct role to it. Also when some server misbehaves the reinstallation becomes a lot less painful then before. You can treat your servers as cattle instead of pets and just tear down and reinstall it.
Infrastructure as Code can give you these benefits:
1: Uniformity. All servers are configured exactly the same, no snowflake servers anymore.
2: Reusability. It becomes very easy to provision a lot of the same servers.
3: Testability. It makes it possible to test your infrastructure changes before applying them to your production environments.
4: Auditable. Because your infrastructure is defined in code, and the code is stored in your version control system you can see who made which changes to the infrastructure.
5: Idempontency. You can run your provisioniong as many times as you want, if there is nothing to do it will not do anything.
Infrastructure as Code can bring the management of your infrastructure to the next level and beyond.