Sooner or later, if you run enough servers, you will get tired of having to log into each server, and run a series of commands to ensure that all of your software is up to date and using the latest version. Software updates happen quite frequently, especially in the world of Linux and open source software. And staying up to date is probably one of the most important things you can do to secure your home lab environment from cyber threats. So in this chapter I thought I would point you to some of the awesome resources I have uncovered for learning basic Linux commands and how to use the command line, writing BASH scripts, and ultimately how to use automation software, specifically a product called Ansible. For this chapter I am mostly going to be linking to Jay LaCroix’s work at Learn Linux TV, mainly because he has very complete playlists that walk you through these topics very comprehensively. But there are other home lab experts that cover these topics as well, and I would encourage you to check out there content. Namely Techno Tim, Christian Lempa, Brandon Lee, and Jim’s Garage.
First to learn basic Linux commands, I highly recommend this playlist from Jay. He covers more than just basic commands. He also explains the file system structure of Linux, how permissions work, managing users, and more. If you are new to Linux, then this video course is for you. And like all the other videos I post, this is basically free education.
Once you get semi proficient at using the Linux terminal or the command line interface as it is called, then the next step will be to learn some basic BASH scripting. Bash scripting is sort of somewhere between entering command in the terminal and actual software coding. Really though it is a bit like writing macros in excel. All you are really doing is writing a test file in a certain format that makes it executable. Within this file you are simply noting a series of commands, the same commands you learned in the Linux Commands for Beginners series. I use bash scripts to automate certain tasks, like getting a server to run backups regularly using the Rsync utility, or to execute certain commands on start up to force my servers into power saving mode.
Finally with those building blocks out of the way, it is worthwhile to learn how to go deeper in automation with Ansible. To use Ansible, you install the software on one computer, and it works “agentlessly”. That is to say you do not have to install software on the servers you are managing (i.e., no “agent” required). Ansible uses secure shell (SSH) to log into all your other servers and execute command. You need to create Playbooks using the now familiar YAML language once again (we saw this with Docker Compose as well). These playbooks list out all the steps you want Ansible to execute. Then you set up Ansible to run at regular intervals using the crontab utility. And that is about it. I am currently using Ansible to keep all my software up to date. But you can use it to do any number of tasks. The neat thing about Ansible is plenty of people share their playbooks on the internet, so you seldom have to start from scratch. Here is Jay’s awesome playlist on Ansible. Be sure to complete all of the steps (well except maybe for the git part. I don’t use github personally).
You may also hear of other automation software, packages like Terraform, Puppet, Chef, OpenTofu, and Salt. I have no experience with these packages, but they are pretty common in the DevOps arena and agile software development. A lot of people will use Terraform along side Ansible, with Terraform being use to provision Infrastructure as Code, and Ansible being used for more configuration and maintenance tasks. I currently don’t have a need for these tools, but maybe that may change some day. Either way, use what works best for you!