Automation the KISS way
No YAML involved
First an inventory
[[hosts]]
id = "backend"
address = "10.0.1.10:22"
user = "root"
tags = ["server", "backend", "myapp"]
vars = { msg = "hi" }
Then a command
$ tricorder -i /path/to/inventory do -- echo "{host.id} says {host.vars.msg}"
Finally, a JSON output
[
{
"host": "backend",
"success": true,
"info": {
"exit_code": 0,
"stdout": "backend says hi\n",
"stderr": ""
}
}
]
Rust API
Add dependency
tricorder = "0.9"
Write your recipe
First, import symbols
use tricorder::prelude::*;
use tricorder::tasks::exec;
use serde_json::json;
Then, build your inventory
let inventory = Inventory::new()
.add_host(
Host::new(Host::id("localhost").unwrap(), "localhost:22".to_string())
.set_user("root".to_string())
.add_tag(Host::tag("local").unwrap())
.set_var("msg".to_string(), json!("hello"))
.to_owned()
)
.to_owned();
Finally, run your tasks
let task = exec::Task::new("echo \"{host.id} says {host.vars.msg}\"".to_string());
Sequentially:
let result = inventory.hosts.run_task_seq(&task).unwrap();
Or concurrently:
let result = inventory.hosts.run_task_parallel(&task).unwrap();
The result is a serde_json::Value
:
println!("{}", result);
Build and run
$ cargo run
Backstory
Ansible is a great tool for automation. But it suffers from the same problem of many such tools: a big pile of custom YAML DSL.
YAML is used to provide a declarative syntax of your automated workflow. This is nice for simple use cases, but automation can become rather complex very quickly.
Once those tools start implementing:
- control flow structures (conditions, loops)
- variable assignations
- modules
- package management
- …
Your YAML files become a programming language with terrible developer experience.
tricorder aims to fix this. It gives you a single tool to perform tasks on
multiple remotes. You then use your common UNIX tools like bash
, jq
, curl
,
etc… to compose those tasks together.
The name comes from Star Trek’s Tricorder, a multifunction hand-held device to perform sensor environment scans, data recording, and data analysis. Pretty much anything required by the plot.
The main goal of tricorder is to provide the basic tools to perform tasks on remote hosts and get out of your way. Allowing you to integrate it with any scripting language or programming language of your choice, instead of forcing you to develop in a sub-par custom YAML DSL.
Spock stared hard at his tricorder, as if by sheer will he might force it to tell him the answer to his questions.