
Pyinfra – automate infrastructure super fast at scale - drcongo
https://pyinfra.com
======
Fizzadar
I wrote pyinfra! If anyone has questions/suggestions/issues I'm more than
happy to answer :)

~~~
BiteCode_dev
I'm looking for an alternative to ansible and fabric 2, some kind of
middleground, and pyinfra looks like something I want to give a try to.

Is there any way to attach the deployement scenario in a Python object ?

All the examples I see are global functions called at a root of a module.

How do I make a scenario pluggable? Reusable? Introspectable?

~~~
Fizzadar
> Is there any way to attach the deployement scenario in a Python object ?

It is possible to use pyinfra as a Python API, but this is not currently
officially supported/may not follow semver, example:
[https://github.com/Fizzadar/pyinfra/blob/master/examples/api...](https://github.com/Fizzadar/pyinfra/blob/master/examples/api_deploy.py).

> How do I make a scenario pluggable? Reusable? Introspectable?

pyinfra comes with builtin support for packaging "deploys" as Python packages,
see:
[https://pyinfra.readthedocs.io/en/v0.14.5/api/deploys.html](https://pyinfra.readthedocs.io/en/v0.14.5/api/deploys.html),
an example: [https://github.com/Fizzadar/pyinfra-
docker](https://github.com/Fizzadar/pyinfra-docker).

~~~
BiteCode_dev
Thanks. I like the fact you can do a quick and dirty script, but the wrap it
up in tasks if you want.

------
usrme
Sorry if this seems willfully ignorant, but what advantage does this provide
over just using something like Ansible?

~~~
sly010
Ansible's pretend-declarative yaml doesn't add any value, while forcing you to
use patterns that rarely match your use-case. It should have been a python
library without all the yaml from the beginning.

That said, pyinfra seems to be making the same mistakes (being a tool instead
of a library, prescribing a folder structure, not letting me create my own
abstractions), so you are right that it provides no advantage over Ansible.

~~~
1337shadow
Well then maybe this is more for you yourlabs.io/oss/shlax (it's still in
development, check the pipeline build job to see some outputs)

But honestly pyinfra seems like the clean Ansible rewrite for people who like
both devops and python programing, pyinfra looks like the next major version
of Ansible.

~~~
BiteCode_dev
Thanks for sharing Shlax, I didn't know about it, and at first glance, I like
the design choices: encapsulate task, pass the target object so you can mock
it for testing, use await to delegate I/O...

~~~
1337shadow
Shlax still has to prove it can do what it aims with the simple design it
strives to keep.

------
sandGorgon
have you looked at Pulumi ?

[https://www.pulumi.com/docs/reference/pkg/python/pulumi/](https://www.pulumi.com/docs/reference/pkg/python/pulumi/)

[https://www.pulumi.com/blog/programming-the-cloud-with-
pytho...](https://www.pulumi.com/blog/programming-the-cloud-with-python/)

~~~
BiteCode_dev
It seems more complementary than a competition, as Pulumi targets clouds,
while pyinfra has a lot of tools for self hosting.

------
ghostwriter
What advantages does Pyinfra have over NixOps?

[https://github.com/NixOS/nixops](https://github.com/NixOS/nixops)

~~~
jackhalford
> NixOps is a tool for deploying to NixOS machines in a network or the cloud

seems like pyinfra is OS agnostic.

~~~
zoom6628
Just checked out the NixOps manual
[https://nixos.org/nixops/manual/](https://nixos.org/nixops/manual/) and it
seems able to deploy to NixOS machines on any cloud or LAN platform. But i
also do not find any mention of it being able to deploy non-NixOS servers.

~~~
ghostwriter
The question is why would you want to have non-nixos servers in that case. If
the goal is to have super-fast automation, you still need to unify your setup
around something common. I see more benefits in unifying around NixOS than in
unifying around Ansible/Pyinfra, as the latter require me to specify my infra
in terms of low-level OS- and distro-specific package managers, that would
eventually define the same lack of "OS agnostic portability".

------
totetsu
isn't there another python writable iac project?

~~~
eliaspro
\- Pulumi [1], which supports amongst many other languages Python as well

\- SaltStack [2], which has a broad range of execution and state modules, uses
by default a "Master/Minion" architecture, but can be used push-based through
"salt-ssh" [3] as well

\- POP/Idem [4] - which originates in the concept of idempotent SaltStack
states, but exposes this functionality as Python code and uses the POP
paradigm [5] coined by SaltStack's founder Thomas Hatch. A lot of SaltStack
itself will quite likely move towards this architecture in the foreseeable
future as well

[1] [https://www.pulumi.com/docs/](https://www.pulumi.com/docs/) [2]
[https://github.com/saltstack/salt/](https://github.com/saltstack/salt/) [3]
[https://docs.saltstack.com/en/latest/topics/ssh/index.html](https://docs.saltstack.com/en/latest/topics/ssh/index.html)
[4]
[https://gitlab.com/saltstack/pop/idem](https://gitlab.com/saltstack/pop/idem)
[5] [https://pop.readthedocs.io](https://pop.readthedocs.io)

~~~
totetsu
Thank you

------
whalesalad
This sounds like Capistrano rewritten in Python?

------
eeZah7Ux
How do you prevent human error from breaking production?

~~~
1337shadow
Play your stuff on a staging server first, and if possible on a container or
vm in the test pipeline of your infra code.

And well, start with a backup and be careful when you're working in production
but that's common sense right ?

~~~
eeZah7Ux
Staging works well in my experience. How can you benefit from a test pipeline
and a staging system with tools that bypass it and ssh right into the
production systems?

------
knodi
ya fix pip and pipenv first. Not starting any more new python projects.

~~~
nickthemagicman
Whats your issue with it? Asking as a noob to python package management. I've
always used venv and pip and didn't even know pipenv existed until I read your
post. Should it be avoided?

~~~
drcongo
Personally I'd recommend Poetry [1] at this point for Python package
management. 99% of the time it works perfectly and keeps out of your way.
There's also a lot of good info in the comments here [2]

[1] [https://python-poetry.org](https://python-poetry.org)

[2]
[https://news.ycombinator.com/item?id=23380113](https://news.ycombinator.com/item?id=23380113)

