One way to achieving this is using the ansible API which all information is listed here:

You can also find a library that will do this for you.

As an alternative, you can use subprocess, a native library, and run ansible as any other command:

import subprocess
cmd = ["ansible-playbook", "-i", "inventory.ini", "playbook.yml"]
 process = subprocess.Popen(cmd,stdout=subprocess.PIPE) 
 while True: 
         output = str(process.stdout.readline(), encoding="utf-8") 
         if process.poll() is not None: 

    In this case the idea is to print line by line from python. But it can be modified to any other application.

Here some references:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s