1
1
import asyncio
2
- import mimetypes
3
-
4
- import aiohttp
5
2
import yaml
6
3
from os .path import join , dirname
7
4
from aiohttp import web
@@ -20,19 +17,8 @@ def run_playbook(data):
20
17
global task_program
21
18
extra_vars = ' ' .join (['{0}={1}' .format (key , data [key ]) for key in data .keys ()])
22
19
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
+
36
22
37
23
@routes .get ('/' )
38
24
async def handle_index (_ ):
@@ -102,4 +88,6 @@ async def post_config(request):
102
88
103
89
app = web .Application ()
104
90
app .router .add_routes (routes )
91
+ app .add_routes ([web .static ('/static' , join (PROJECT_ROOT , 'app' , 'static' ))])
92
+ app .add_routes ([web .static ('/results' , join (PROJECT_ROOT , 'configs' ))])
105
93
web .run_app (app , port = 9000 )
0 commit comments