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.91k stars 382 forks source link

Ansible module operation #904

Open Sispheor opened 2 years ago

Sispheor commented 2 years ago

Description

Hello there.

I tried to find an Ansible Operation that could wrap like a proxy any Ansible module to profit from what has been done by this framework. But it seems that it doesn't exist yet.

Describe the solution you'd like

Ansible modules are pretty simple, they take arguments and return a json dict. So a mapper could be done right?

I was thinking about this kind of usage:

result = ansible.module(
    name="module_name",
    module_args={
      "arg_key": "arg_val"
    }
)
Fizzadar commented 2 years ago

My understanding of Ansible modules is they get uploaded to the remote host and then called with the system python? That understanding is a few years old though! Seems like this could be done, although I think it falls out of scope for builtin operations (but a pyinfra-ansible-operation package would be great).

Ref: #906

Sispheor commented 2 years ago

Yes indeed this should not be a part of the core.

When you mention package, you think about a standard python package we can find in pypi? Because I don't see in the doc corresponding notion of Role/Collection from the Ansible world. (hope it's fine if I compare your project to Ansible)

If for example somebody want to propose something like the project Kubespray? What would be the wrapper around the used script and operator?

In Ansible world:

BTW, you should add a Gitter chat so people could discuss about the project, new features, share info, give support to new users, etc..

I there any page somewhere to share to the community a link to our package if we make one?

Thank you !

ccrvlh commented 2 years ago

From what I understand an Ansible role is sort of a collection of playbooks. Although you usually call roles through playbooks as well. So in very simple terms you have collection > role > playbook > module.

Ansible Module is somewhat equivalent to PyInfra operators. Ansible Playbooks are somewhat equivalent to Pyinfra Deploy

As far as I understand there's no specific parallel for Collections and Roles, although you could just have a bunch of files that would work like playbooks and a deploy.py file acting as if it was a role. This is probably a good example.

TBH I think the approach is a bit different so comparisons are not that fair.

That being said, one possible approach would be to have a generic Ansible operator (somewhat like an Ansible CLI wrapper - Salt does something like this), and/or a Suitable operator, which basically wraps Ansible modules, so one could use any Ansible module through Suitable programmatically without having a significant extra cost to maintenance of core modules, its basically exactly the way @Sispheor described on the OP.

The positive side of this approach would be for Pyinfra to support virtually all of Ansible modules out of the box.