Ansiblator - makes Ansible api more Pythonic

This wrapper allows more easier way how to use Ansible in Python. Chain commands without without playbooks. More like Fabric. With this Ansible can be more powerfull and it will allow to chain commands with python commands. Ansible documentation is on .

API is now trying to feel like Fabric, but it's still not complete, there will be some changes.


This article is quite old. Please do not follow it > we do not use it anymore.

Get started

For instalation you can download package and then just unpack package and use it:

python install

or install by pip:

pip install ansiblator


For most quickest example you can just create your ansible host file named ansible_hosts inside your home directory or give full path to file.

Ansiblator is mainly using file such as in ~/ansible_hosts.


import ansiblator.api as an
ans = an.Ansiblator()
ret = ans.local("uname -a", now=True, use_shell=True)"uname -a", now=True)
ans.copy(src="/tmp/aabc.csv", dest="/tmp/",pattern="pc",now=True)

specify ansible hosts file and select pattern:

ans = an.Ansiblator(inventory="/tmp/ansible_file", pattern="pc")

use dictionary to create inventory:

inv = {'pc':[{'ssh_host':'', 'ssh_user':'test_user', 'su_user':'root'},
            {'ssh_host':'', 'ssh_user':'test_user2', 'su_pass':'paasswd','su_user':'root'}]}
ans = an.Ansiblator(inventory=inv)"uname -a", now=True)

prepare commands and run after:

ans = an.Ansiblator(run_at_once=False)
ans.get(src="/tmp/file", dest="/tmp/")
ans.get(src="/tmp/file2", dest="/tmp/")

make custom class:

class Automatization(Ansiblator):

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

use custom class and more patterns together:

ans = Automatization(pattern=['servers', 'production', 'test', 'pc'])

With this, you can create full commands or functions and just pass to them pattern and run at the end.

Need all modules inside Ansible?:

ans = an.Ansiblator()
#now you should be able to do >
#or even
ans.pip(name="six", virtualenv="/tmp/venv", virtualenv_site_packages="yes")

More information

Ansiblator automatically saves returned json values for actuall runs, so you can use them for testing and conditions. For example


return_code = ans.local("uname -a", now=True, use_shell=True)


return_code = ans.local(["uname", "-a"], now=True, use_shell=False)


  • make more tests
  • improve logging
  • improve DictToInventory mapper, so more options are possible, such as groups and so on


  • ability to run on more patterns
  • fixes on more runs
  • run all modules on ansible

Preparation, production, furniture and interiors. Service - prepare technical documentation for furnture production.

© 2013-2023 | Contact us | Legal