pyinfra-dev / pyinfra

pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine and Docker containers. Fast and scales from one server to thousands.
https://pyinfra.com
MIT License
3.87k stars 377 forks source link

LXD connector #677

Open benoitjpnet opened 2 years ago

benoitjpnet commented 2 years ago

Hello,

The goal would be to have a LXD connector so we can use it like:

pyinfra @lxd/<containerName> [...]

In the back-end it should probably use lxc exec <containerName> -- <command>

Related: #388

Thanks,

fingon commented 2 years ago

I'd like to have this and have the connectors somehow composable, as the machine I am running pyinfra from ISN'T one of those running lxc. Due to that, lxcssh (or something would be also nice to have.

I might tackle writing something for my use, although as my use is really (at the moment at least) limited I'm tempted just skipping pyinfra and doing stuff by hand :-) Still, keeping an eye on this issue.

I suppose one option would be just writing pyinfra stuff which ssh's pyinfra configs to machines, and then runs them with lxc connector if any; without lxc connector, it could also copy them to the lxc container and run pyinfra there but I'd rather not install pyinfra in N places if one is enough.

Fizzadar commented 1 year ago

The @dockerssh connector implements this kind of thing, but it's not a composable combination of @ssh and @docker connectors (which would be awesome to have).

dontlaugh commented 1 year ago

I don't know which approach is better, but the LXD project maintains an official Python SDK

https://github.com/lxc/pylxd/blob/master/setup.cfg#L16

Shelling out to lxc works fine, as well. This is how the Puppet Bolt integration was created for LXD. That was Ruby, though, so using an official library wasn't an option.

Both have their advantages. Relying on the lxc binary works, and is simpler, but usage of the SDK would likely make implementing an @lxdssh feature easier? idk.

@Fizzadar What's your preference regarding taking on python deps?