home | hardware | software | misc | about | rss

Cloning a System with Ansible


I've wanted a tool to take an existing system and create an Ansible playbook that will duplicate it. This would let me set up a laptop how I want it, and then quickly reproduce that setup on a different laptop without having to remember what I did. As far as I know, there's nothing out there that does this. Since the only way to find out is to spend hours writing it myself and then discover someone else way better than me has done it, I wrote a small Python script called ansible-clone for this purpose.

It will detect all the installed packages on the system on which its running, find all the enabled services, and include the contents of any config files you provide it, and generate an Ansible playbook to duplicate this. The config files are provided by giving ansible-clone an INI file that looks something like this:

path = /home/joe/.spectrwm.conf

path = /etc/pf.conf

The contents of these files will be placed in the playbook to be copied to those same paths when Ansible is run.

Putting it all together, you would do something like this:

$ ansible-clone -c configs.ini -f playbook.yml

The resulting file playbook.yml can then be copied to a different system, and you can run ansible-playbook on it to duplicate the system from which it came.

The script is super rough and a work in progress, but it produces valid yaml, which is proof that there is a God, because any yaml that is actually valid is to be considered a miraculous event. Currently it only supports FreeBSD and OpenBSD, but adding support for other operating systems is just a matter of adding in the proper package and service listing commands, and instructions are in the README if you want to hack on it. Eventually I'd like to have it support Linux too, but my priority right now is getting it working well on the BSDs.

The project is on Github if you want to give it a try. Patches are welcome.