-
|
Hi, we're (together with @yagarea) looking at rewriting our home server's setup scripts from Ansible to pyinfra. One thing we ran into is that we didn't find any way to run operations on another host (a replacement for Ansible's Our main usecase for this is a script that creates a new Incus container. It needs to run commands on the host, to create the container and change its config, then in the container itself, to set up networking and install basic packages. Is there some straightforward way to do this I just missed, or is there some reason this can't be don with pyinfra? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
|
This can probably be done with pure python idk how, but this would be great for Pyinfra scalling |
Beta Was this translation helpful? Give feedback.
-
Hi, what about something like this ? # inventory.fr
incus_servers = [
("my-incus-host", {}),
]
containers = ['("c1", {})]
# deploy.py
from pyinfra import host
from pyinfra.operations import ...
# Use Hostname
if host.name == "my-incus-host"
incus.instance(
name="Create container c1",
instance="c1
)
if "containers" in host.groups:
apt.packages(
name="Install base packages",
packages=["vim", "curl"]
) |
Beta Was this translation helpful? Give feedback.
-
|
I think I finally understood the key point about In Ansible, a task still belongs to the current host (loop/context), but is executed on another host via In pyinfra, there’s no such split: an operation always runs on the host it targets. If you want something to happen on another host, you just target that host directly. There’s no concept of “delegating” mid-task. So rather than trying to replicate Key difference
|
Beta Was this translation helpful? Give feedback.
I think I finally understood the key point about
delegate_to, and why you couldn’t find an equivalent in pyinfra.In Ansible, a task still belongs to the current host (loop/context), but is executed on another host via
delegate_to. So you get this mix of “who the task is for” vs “where it runs”.In pyinfra, there’s no such split: an operation always runs on the host it targets. If you want something to happen on another host, you just target that host directly. There’s no concept of “delegating” mid-task.
So rather than trying to replicate
delegate_to, the intended approach in pyinfra is to structure your deploy so that each operation is applied to the right hosts explicitly (and split st…