Slackware & Qemu - Part 2: Rust vs Ansible
Interesting title, isn't it ? How Rust can be compared with Ansible ? System langugage vs infrastructure tool ? Well, it can as long as they are used in the same manner. And believe, they can be used in the same manner. So where did I get the idea to use Rust as a configuration language ? Well, it all started with using Ansible throughout the several years now. It's really nice tool, with good idea to it, it has it's bad sides, but overall it's been around for years and most likely will be for years to come. However, something which seemed like a bad design, was lack of backwards compatibility with constantly changing modules. One of the reasons might be it's based on Python, which is changing pretty fast, so there is no chance to keep everything compatibile. But back to my reasons - there was a year, when I was working with Zabbix and I was using Ansible to configure it. Sure, it was nice (at the time of that there was no items module, which was bad enough), quite fast and get done (mostly) what I wanted. And then items module were added - what a blast ! I figured, they almost won it for me. So I configured Zabbix, get back to my other DevOps tasks and way to go. Several months later, new guy come to assist, and he's asking whether we are using Ansible, so my answer was: yes, be my guest, there are the playbooks. And what a surprise was, when I found out, Ansible changed core module responsible for Zabbix auth ! All my playbooks needed to be rewritten. I was really surprised, as this was suboptimal solution to say the least. When it comes to Zabbix itself in Ansible territory, they made a strange decision - SSH into Zabbix machine, so API calls can be send to localhost (?!). Zabbix API is one of the good things about it, especially when you can generate token and use it to calls, without storing it, so there is no need to SSH as this add another layer and time to execution.
So after some time, getting into more Rust I figured - why not use Rust to configure system ? It should be faster and compatibile enough with what you are writing. Well, let's try it out. First let's see if there are any crates that covers absolute basics in SysOps work - SSH. And there are few ! Nice. So I've checked and choice of mine was to use russh, which is currently maintained and have different kind's of session - whether it's interactive or not. Seemed like a bit advanced start into this adventure, as syntax is not super easy, but after trial and error I got where I needed.
I've prepared 10 VM's (check my other post) with 1 CPU/512 MB Ram and started test. First one was:
1. Execute 3 simple commands (ls -la, df -h, touch file.test) in one session:
a) Ansible (with skipping all unnecessary steps) - ~45s
b) Rust (debug build binary) - ~16s
2. Execute 3 above commands in separate sessions:
a) Ansible - ~1m40s,
b) Rust - ~45s
So as you can see, Rust have clear advantage, being ~50% - ~60% faster then Ansible. And that's being performed on local network with ping less than 0.1ms ! Further tests will come soon.
In summary, sure, Rust has "steep learning curve", especially at the beginning, but it's well worth it - time of execution and it's modularity. It's build for reliability and execution time, so with infrastructure at scale might become more crucial as the time will go on. It's worth to try. You can try it yourself by using devops-armory library from crates.io, which is using TOML file as source of information.

