main
root 2023-12-19 13:48:06 +01:00
parent 8ea55ac5e2
commit aac485401b
8 changed files with 54 additions and 26 deletions

Binary file not shown.

20
app.py
View File

@ -3,22 +3,11 @@ import os
from flask import Flask, render_template, request, redirect, url_for from flask import Flask, render_template, request, redirect, url_for
from flask_socketio import SocketIO from flask_socketio import SocketIO
from config import *
app = Flask(__name__) app = Flask(__name__)
socketio = SocketIO(app) socketio = SocketIO(app)
FILE_PATH = '/data/interface/fichier.txt'
class path:
ansible_scripts = '/data/Ansible-Playbook/'
default_hosts = '/data/Ansible-Playbook/hosts'
binary = '/usr/bin/ansible-playbook '
class flask_config:
port=8000
host='0.0.0.0'
thread=True
debug=False
@app.route('/') @app.route('/')
def index(): def index():
playbooks=[] playbooks=[]
@ -33,19 +22,16 @@ def edit():
FILE_PATH = path.ansible_scripts+request.form['file_edit'] FILE_PATH = path.ansible_scripts+request.form['file_edit']
with open(FILE_PATH, 'r') as file: with open(FILE_PATH, 'r') as file:
file_content = file.read() file_content = file.read()
return render_template('edit_file.html', file_content=file_content, filepath=FILE_PATH) return render_template('edit_file.html', file_content=file_content, filepath=FILE_PATH,file_name=request.form['file_edit'])
@app.route('/edit_file', methods=['POST']) @app.route('/edit_file', methods=['POST'])
def edit_file(): def edit_file():
new_content = request.form.get('file_content') new_content = request.form.get('file_content')
FILE_PATH = request.form.get('file_path') FILE_PATH = request.form.get('file_path')
print("edit "+FILE_PATH)
with open(FILE_PATH, 'w') as file: with open(FILE_PATH, 'w') as file:
file.write(new_content) file.write(new_content)
return redirect(url_for('index')) return redirect(url_for('index'))
@app.route('/run') @app.route('/run')
def run(): def run():
return render_template('run.html') return render_template('run.html')

17
config.py 100644
View File

@ -0,0 +1,17 @@
'''
ansible_scripts : location of the playbooks
default_hosts: default hosts file path
binary : ansible binary path (use "whereis ansible-playbook" to find it)
'''
class path:
ansible_scripts = '/data/Ansible-Playbook/'
default_hosts = '/data/Ansible-Playbook/hosts'
binary = '/usr/bin/ansible-playbook '
class flask_config:
port=8000
host='0.0.0.0'
thread=True
debug=False

View File

@ -6,3 +6,7 @@
padding-top: 10px; padding-top: 10px;
border-color:#ccc; border-color:#ccc;
} }
.notes {
font-style: italic;
font-size: xs-small;
}

View File

@ -14,7 +14,10 @@
<link href="{{url_for('static', filename = 'style.css')}}" rel="stylesheet"> <link href="{{url_for('static', filename = 'style.css')}}" rel="stylesheet">
</head> </head>
<body> <body>
<title>Ansinterface</title>
<center><h1 class="display-6">Ansinterface</h1></center>
<div class="container"> <div class="container">
<br><br>
{% block content %}{% endblock %} {% block content %}{% endblock %}
</div> </div>
<script> <script>

View File

@ -1,11 +1,16 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block content %} {% block content %}
<a href="/">< Back</a> <div class="card">
<br> <div class="card-header">
Editing <code>{{ file_name }}</code>
</div>
<div class="card-body">
<form method="post" action="{{ url_for('edit_file') }}"> <form method="post" action="{{ url_for('edit_file') }}">
<textarea id="code" name="file_content" class="form-control numbered">{{ file_content }}</textarea> <textarea id="code" name="file_content" class="form-control numbered">{{ file_content }}</textarea><br>
<input type="hidden" id="file_path" name="file_path" value="{{ filepath }}"> <input type="hidden" id="file_path" name="file_path" value="{{ filepath }}">
<a href="/" class="btn btn-info">Back</a>
<button type="submit" value="Save Changes" class="btn btn-info" >Save</button> <button type="submit" value="Save Changes" class="btn btn-info" >Save</button>
</form> </form>
</div>
</div>
{% endblock %} {% endblock %}

View File

@ -7,18 +7,30 @@
<div class="card-body"> <div class="card-body">
<form id="ansibleForm"> <form id="ansibleForm">
<label for="playbook">Playbook <span style="color:red"></span></label> <label for="playbook">Playbook <sup style="color:red"></sup></label>
<select id="playbook" class="form-control" name="playbook" placeholder="Profile" required> <select id="playbook" class="form-control" name="playbook" placeholder="Profile" required>
{%for file in list %} {%for file in list %}
<option value={{ file }}>{{ file }}</option> <option value={{ file }}>{{ file }}</option>
{%endfor%} {%endfor%}
</select> </select>
<label for="hosts">Hosts:</label> <!-- -->
<div class="row">
<div class="col">
<label for="hosts">Hosts</label>
<input type="text" name="hosts" class="form-control" placeholder="/path/to/inventory"> <input type="text" name="hosts" class="form-control" placeholder="/path/to/inventory">
<div class="notes">If empty will use default settings.</div>
</div>
<div class="col">
<label for="argument">Arguments</label> <label for="argument">Arguments</label>
<input type="text" name="argument" class="form-control" placeholder="-e "><br> <input type="text" name="argument" class="form-control" placeholder="-e ">
</div>
<div class="col">
<label for="limitation">Limitation</label> <label for="limitation">Limitation</label>
<input type="text" name="limitation" class="form-control" placeholder="-l "><br> <input type="text" name="limitation" class="form-control" placeholder="-l ">
<div class="notes">Separate your servers with coma (example: localhost,server1...).</div>
</div>
</div>
<br> <br>
<button type="button" class="btn btn-info" onclick="submitForm()">Run</button> <button type="button" class="btn btn-info" onclick="submitForm()">Run</button>
</form> </form>

View File

@ -1,12 +1,13 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block content %} {% block content %}
<a href="/">< Back</a>
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
Command output Command output
</div> </div>
<div class="card-body"> <div class="card-body">
<div id="output" class="numbered"></div> <div id="output" class="numbered"></div>
<br>
<a href="/" class="btn btn-info">Back</a>
</div> </div>
</div> </div>