Skip to main content

Ansiblator - makes Ansible api more pythonic

Project description

Ansiblator
==========

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 http://docs.ansible.com/.
API is now trying to feel like Fabric, but it's still not complete, there
will be some changes.

Get started
===========

For instalation you can download package and then just unpack package from
https://pypi.python.org/pypi/ansiblator and use it::

python setup.py install

or install by pip::

pip install ansiblator


Quickstart
==========

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.

code::

import ansiblator.api as an
ans = an.Ansiblator()
ret = ans.local("uname -a", now=True, use_shell=True)
ans.run("uname -a", now=True)
ans.runner("uptime")
ans.run_all()
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':'192.168.0.10', 'ssh_user':'test_user', 'su_user':'root'},
{'ssh_host':'192.168.0.12', 'ssh_user':'test_user2', 'su_pass':'paasswd','su_user':'root'}]}
ans = an.Ansiblator(inventory=inv)
ans.run("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/")
ans.run_all()

make custom class::

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 class and more patterns::

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


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


More information
================

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

testing::

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

or

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

TODO
====

- make more tests
- make automatic translating of methods to ansible modules
- improve logging
- improve DictToInventory mapper, so more options are possible, such as groups and so on

CHANGES
=======

- ability to run on more patterns
- fixes on more runs

Info
====
For more information you can consult functions or actual Ansible documentation.
More information can be also used on http://www.pripravto.cz. You can also
contact us there.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ansiblator-0.5-11-18-10-2014.tar.gz (7.8 kB view details)

Uploaded Source

File details

Details for the file ansiblator-0.5-11-18-10-2014.tar.gz.

File metadata

File hashes

Hashes for ansiblator-0.5-11-18-10-2014.tar.gz
Algorithm Hash digest
SHA256 91872d43987ca1f489e907efccaca41f95a5af95e54d03826fb9f556f476cb09
MD5 7e5f4e1acceeba2bee0615210e7d4031
BLAKE2b-256 cb0a35f1490f9315fc583b2891ed260ca49fc42b79a3e88afb634c7d5e2efe00

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page