Table of Contents
The ‘why’ #
Are you also someone who likes consistency? Do you enjoy deploying Linux desktops, servers? Does not like repetitive tasks? Hours on end to install “stuff”, configure your settings etc?
Look no further! ansible-pull to the rescue! Recently I have worked a lot with Ansible - to rein in some unruly infrastructure, both Linux and Windows - I started using this tool extensively in my home lab. At home, my primary user case is setting up Docker-Compose stack and occasional
k3s deployment. But as a side-project (and since I have pre-ordered a Framework 16 laptop, which I will plan to use for pure Linux, as my dev workhorse), I decided to learn how to manage the configuration of consistent Linux servers with this tool too. Usually, when I set up a new workstation, I spend the first hour installing my tools, and putting my settings in place…something can be swapped with a few minute automated script run, while I make a coffee or check my Medium feed :)
My actual fork can be found here. Currently, I am using the Fabrice branch.
The idea is, I perfect this (for now I focus only on Desktops, and Gnome desktop env; servers and KDE is in the near-term plans!) on VM(s), and once it arrives (early 2024 I have been told), I use this to configure my new laptop; also I plan to rebuild some servers in my home-lab, where this will also come handy.
Now the theory is pretty simple:
- you define your config (’the desired state’) in a repo, telling Ansible what to do
- then with pull you download this configuration
- and the local
ansible-pullbinary (which comes by default with your Ansible install) sets the machine to this state
As opposed to the standard push mode of Ansible (where you run the configuration from a central server), this gives you some flexibility, as you do not have to have a connection to the target host (since you run the task against the
localhost); all you need is a connection to the repository (Github in my case).
In my case, as I am still working out the details, all I did is:
- created a new VM on my laptop’s hyper-v (used Ubuntu 20.04 in this case)
- installed Ansible on this one
- and took a snapshot (just so I can return to the vanilla state after running a pull, while testing)
Once this is done, pretty much things look like this:
Nothing surprising here, standard Ubuntu landscape yes?
Now the first (and more or less the last) step is to issue the command:
sudo ansible-pull -U https://github.com/fabricesemti80/home.ansible.linux-config-with-ansible-pull.git -C fabrice
Should you need an explanation:
sudoelevates to root
-U` tells Ansible what repo to check out
- and since I am not using the default branch,
-Ctells it to use my branch (this last part is not needed, if your code is in the default branch)
After several lines of output, similar to this:
you will reach the end of the play. Normally that would be it, your system would get all the settings you need; but since I install a few things that require a reboot, I also restart my system. (These things include for example the DisplayLink driver needed for my docking station)
After the reboot, I kid-you-not - the wallpaper is not the only thing that got updated:
The pull did several things for me:
- it installed a slew of applications
- copied my settings (including my public ssh key) and profile files to their space
- installed Gnome theme, and set it, along with some extensions and icon theme
- installed fonts that I use
- configured ZSH to replace Bash
and many-many things, that you can explore in the repo. Closing thoughts course, I have a lot to do on this one:
- as of now, I have not found a way to install
homebrew; therefore I will manually install it, and then I can add packages from Brew to be installed
- I tested somewhat this pull on Arch (Endeavor) Linux, but still have some things to iron out there…
But already it saved me several hours of repetitive setup, and taught me a lot about Linux in general!