pyinfra
Getting started
Execute over SSH with options
pyinfra localhost --ssh-port 2222 --ssh-user vagrant exec -- echo "hello world"
Execute within a new docker container
pyinfra @docker/ubuntu:22.04 exec -- echo "hello world"
Execute
pyinfra inventory.py deploy.py
Globales sudo
from pyinfra import config
config.SUDO = True
Server Facts
zB (mittelgut) checken ob Programm installiert ist, im "Playbook":
from pyinfra.facts.server import Which
print(host.get_fact(Which, "vi"))
oder auch so:
from pyinfra import facts
print(host.get_fact(facts.server.Which, "vi"))
und interaktiv muss es so geschrieben werden: (mit Argumenten danach drangehängt)
(venv) morph@sun:~/src/infra$ pyinfra pommes fact server.Which command=tailscale
--> Loading config...
--> Loading inventory...
--> Connecting to hosts...
[pommes] Connected
--> Gathering facts...
[pommes] Loaded fact server.Which (command=tailscale)
--> Fact data for: server.Which (command=tailscale)
{
"pommes": "/usr/bin/tailscale"
}
--> Disconnecting from hosts...