Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thalesmg/turma
Command and control some machines
https://github.com/thalesmg/turma
Last synced: 10 days ago
JSON representation
Command and control some machines
- Host: GitHub
- URL: https://github.com/thalesmg/turma
- Owner: thalesmg
- License: gpl-3.0
- Created: 2022-01-23T19:53:03.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-13T19:04:45.000Z (about 2 years ago)
- Last Synced: 2023-03-05T07:38:55.685Z (over 1 year ago)
- Language: Elixir
- Size: 264 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
* Turma
Very simple and naive application for issuing commands to several
machines in parallel and retrieving results.The main purpose of this is to replace Ansible for some tasks that
require more complex operations, and also to overcome Ansible's
limitations of seemingly running only a few jobs in parallel (which I
known can be increased) and then ofter getting the SSH connection in a
stuck state or losing the connection. If one task takes too long or
gets stuck, the next hosts and the whole playbook crawls to a halt.This project is /not/ for use in production, as it's completely
unsafe.* Setup
Start a ~Legionarius~ node on each machine you want to control, and
one ~Decurio~ to use as the command central. The configuration lives
at ~etc/runtime.exs~ inside the release root directory.On each ~Legionarius~, define its ~id~ as the endpoint you'll use to
connect to it:#+BEGIN_SRC elixir
config Turma.Legionarius,
bind: {"10.10.1.41", 19876},
id: "server-0.some.cluster:19876"
#+END_SRCOn ~Decurio~, define the inventory and then start it up:
#+BEGIN_SRC elixir
config Turma.Decurio,
inventory: %{
"tag1" => [
"server-0.some.cluster:19876",
"server-1.some.cluster:19876",
# ...
],
"tag2" => [
"server-1.some.cluster:19876",
"other-server-0.some.cluster:19876",
],
# ...
},
name: "my-decurio"
#+END_SRC** Examples
Run something on all nodes:
#+BEGIN_SRC elixir
alias Turma.Decurio
Decurio.run(fn -> node() end)
#+END_SRCRun something on hosts with a specific tag:
#+BEGIN_SRC elixir
alias Turma.Decurio
Decurio.run("tag", fn -> node() end)
#+END_SRCRun something on hosts whose endpoint match a regex:
#+BEGIN_SRC elixir
alias Turma.Decurio
Decurio.run(~r/^some-host-[0-9]+/, fn -> node() end)
#+END_SRCRun something on hosts filtering directly on the inventory:
#+BEGIN_SRC elixir
alias Turma.Decurio
filter = fn inventory ->
inventory
|> Map.fetch!("tag")
|> Enum.take_every(3)
end
Decurio.run(filter, fn -> node() end)
#+END_SRCGet the results of a job (may change as each node returns results):
#+BEGIN_SRC elixir
alias Turma.Decurio
{:ok, id} = Decurio.run(fn -> node() end)
Decurio.get(id)
#+END_SRCGet all jobs:
#+BEGIN_SRC elixir
alias Turma.Decurio
Decurio.get_all()
#+END_SRCBlock until a job is done:
#+BEGIN_SRC elixir
alias Turma.Decurio
{:ok, id} = Decurio.run(fn -> node() end)
res = receive do
{:job_finished, ^id} -> Decurio.get(id)
after
10_000 -> :timeout
end
#+END_SRC