Ansible and ease of use in Python

Hello,

several months ago together with my brother we have started to work on Ansiblator > Python wrapper modul which makes Ansible more easy to use in Python itself. It is just base class which should make other corresponing efforts to be quicker and easier. Other part is DictToInventory converter.

import ansiblator.api as an
ans = an.Ansiblator()
ans.run("uname -a", now=True)
ans.run("uptime")
ans.run_all()
ans.user(name="hugo", sudo=True)
ans.copy(src="/tmp/aabc.csv", dest="/tmp/",pattern="pc",now=True)

Before I had talked with project leader by email (mainly about license). Main thing why I am writing here is because, now it feels, that it could be improved more, for example maybe somehow implemented inside of Ansible modules. Another thing is to improve it itself. Ansiblator always always uses new runner for each run, it can get really slow beacause it is not using playbooks-runner (it continues to stay in connection). So the question if somehow we could improve this, to be Ansible more usefull inside Python it self. For example I think that Fabric api is more clean and more nicer to use in Python itself.

another main use are custom classes:

`

class Automatization(Ansiblator):

    def update_server(self, su=True,sudo=False):
        self.run("apt-get update", su=su, sudo=sudo)
        self.run("apt-get upgrade -y", su=su, sudo=sudo)

#use custom class and more patterns together:

ans = Automatization(pattern=['servers', 'production', 'test', 'pc'], sudo=True)
ans.update_server()

`

There is probably another similar project on https://pypi.python.org/pypi/suitable/

Anyway, we will continue on work for ansiblator, as we are already using it for our service, where we need direct control from Python.

Regards,
zd

Hi, we’re currently refactoring Ansible in a “v2/” tree which will change the way the Runner API works a bit.

Please stay tuned.

The above project will most definitely be broken by this change.

Hello,

well that’s good to hear. And if it will make main Ansible API for Python more attractive and easier, then it’s probably perfect and better than this project.
Anyway, thanks for information. Do you already have some kind of plan/idea how it will turn out, and if it will be more useful in Python itself?

Thanks

The v2 tree Michael mentioned is in the ansible repo, so you can at least
see where things are headed:

https://github.com/ansible/ansible/tree/devel/v2/ansible

Yeah, no top end Runner API established just yet.

Soon.