11import asyncio
2- import mimetypes
3-
4- import aiohttp
52import yaml
63from os .path import join , dirname
74from aiohttp import web
@@ -20,19 +17,8 @@ def run_playbook(data):
2017 global task_program
2118 extra_vars = ' ' .join (['{0}={1}' .format (key , data [key ]) for key in data .keys ()])
2219 task_program = ['ansible-playbook' , 'main.yml' , '--extra-vars' , extra_vars ]
23- vars = PlaybookCLI (task_program ).run ()
24- # TODO: filter only necessary vars
25- return vars
26-
27- @routes .get ('/static/{path}' )
28- async def handle_static (request ):
29- filepath = request .match_info ['path' ]
30- mimetype = mimetypes .guess_type (filepath )
31- try :
32- with open (join (dirname (__file__ ), 'static' , * filepath .split ('/' )), 'r' ) as f :
33- return web .Response (body = f .read (), content_type = mimetype [0 ])
34- except FileNotFoundError :
35- return web .Response (status = 404 )
20+ return PlaybookCLI (task_program ).run ()
21+
3622
3723@routes .get ('/' )
3824async def handle_index (_ ):
@@ -102,4 +88,6 @@ async def post_config(request):
10288
10389app = web .Application ()
10490app .router .add_routes (routes )
91+ app .add_routes ([web .static ('/static' , join (dirname (__file__ ), 'static' ))])
92+ app .add_routes ([web .static ('/results' , join (dirname (dirname (__file__ )), 'configs' ))])
10593web .run_app (app , port = 9000 )
0 commit comments