Beispiel #1
0
def SubmitPlay(request):    
    import jinja2
    from tempfile import NamedTemporaryFile
    import os

   
    html = ''

    inventory = """
    [current]
    {{ public_ip_address }}
    """
    # for (name,value) in request.GET:
        
        # if name=='Servers':
            # html=html+str(value+'\n')
   

    html=request.GET['Severs']
    inventory_template = jinja2.Template(inventory)
    rendered_inventory = inventory_template.render({
        'public_ip_address': html    
        # and the rest of our variables
    })

    # Create a temporary file and write the template string to it
    hosts = NamedTemporaryFile(delete=False)
    hosts.write(rendered_inventory)
    hosts.close()
    
    print(hosts.name)

    import ansiblepythonapi as myPlay
    args=['/home/ec2-user/playss/AnsiblePlus/test.yml']
    # args.append('-i')
    # args.append(hosts.name)
    message=myPlay.main(args)

    objects=[]
    for runner_results in myPlay.message:              
        values=[]
        for (host, value) in runner_results.get('dark', {}).iteritems():
            try:
                values.append(host)
                values.append(value['failed'])
                values.append(value['msg'])    
                objects.append(values)
            except:
                pass
        for (host, value) in runner_results.get('contacted', {}).iteritems():
            try:
                values.append(host)
                values.append(value['failed'])
                values.append(value['msg'])    
                objects.append(values)
            except:
                pass
        # for msg in pb.stats.output():   
    context=Context({'Summary':objects})
    return render(request, 'AnsibleResponce.html',context)
Beispiel #2
0
def SetupPlay(request):
    import ansiblepythonapi as myPlay
    args=['test.yml']
    message=myPlay.main(args)
    html=''
    html+='<table border=1 cellspacing=5 cellpadding=5>'
    
    for runner_results in myPlay.message:      
        # message.append(runner_results)
        for (host, value) in runner_results.get('dark', {}).iteritems():
            html+='<tr>'            
            html+='<td>'+host+'</td>'
            html+='<td>'+str(value['failed'])+'</td>'
            html+='<td>'+str(value['msg'])+'</td>'
            html+='</tr>'    
        for (host, value) in runner_results.get('contacted', {}).iteritems():
            html+='<tr>'            
            html+='<td>'+host+'</td>'
            html+='<td>'+str(value['failed'])+'</td>'
            html+='<td>'+str(value['msg'])+'</td>'
            html+='</tr>'
        # for msg in pb.stats.output():               
        # print msg
    html+='</table>'
    return HttpResponse(html)