commit 8ea55ac5e2c05403fa7e7122451750f36ab373d1 Author: root Date: Tue Dec 19 11:32:13 2023 +0100 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/app.py b/app.py new file mode 100644 index 0000000..78f33ba --- /dev/null +++ b/app.py @@ -0,0 +1,82 @@ +import subprocess +import os +from flask import Flask, render_template, request, redirect, url_for +from flask_socketio import SocketIO + +app = Flask(__name__) +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('/') +def index(): + playbooks=[] + for file in os.listdir(path.ansible_scripts): + if file.endswith(".yml"): + playbooks.append(file) + return render_template('index.html',list=playbooks) + +@app.route('/edit', methods=['POST']) +def edit(): + if request.form['file_edit']: + FILE_PATH = path.ansible_scripts+request.form['file_edit'] + with open(FILE_PATH, 'r') as file: + file_content = file.read() + return render_template('edit_file.html', file_content=file_content, filepath=FILE_PATH) + +@app.route('/edit_file', methods=['POST']) +def edit_file(): + new_content = request.form.get('file_content') + FILE_PATH = request.form.get('file_path') + print("edit "+FILE_PATH) + + with open(FILE_PATH, 'w') as file: + file.write(new_content) + return redirect(url_for('index')) + + +@app.route('/run') +def run(): + return render_template('run.html') + +@socketio.on('submit_playbook') +def handle_submit_playbook(data): + playbook = data['playbook'] + hosts = data['hosts'] + argument = data['argument'] + limitation = data['limitation'] + if playbook: + command = path.binary+path.ansible_scripts+playbook + if limitation: + command = command +" -l "+limitation + if argument: + command = command +' -e "'+argument+'"' + if hosts: + command = command +" -i "+inventory + else: + command = command +" -i "+path.default_hosts + print(command) + process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1) + while True: + output = process.stdout.readline() + if output == '' and process.poll() is not None: + break + if output: + socketio.emit('ansible_output', {'data': output.strip()}) + + process.wait() + socketio.emit('ansible_output', {'data': '*** La tâche Ansible est terminée ***'}) + +if __name__ == '__main__': + socketio.run(app, host=flask_config.host, port=flask_config.port, debug=flask_config.debug) diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..c73299b --- /dev/null +++ b/static/style.css @@ -0,0 +1,8 @@ +#numbered { + background: url(http://i.imgur.com/2cOaJ.png); + background-attachment: local; + background-repeat: no-repeat; + padding-left: 35px; + padding-top: 10px; + border-color:#ccc; +} diff --git a/templates/arch/base.html b/templates/arch/base.html new file mode 100644 index 0000000..2adeba1 --- /dev/null +++ b/templates/arch/base.html @@ -0,0 +1,12 @@ + + + + + + + + + +{% block content %}{% endblock %} + + diff --git a/templates/arch/index.html b/templates/arch/index.html new file mode 100644 index 0000000..9668a9b --- /dev/null +++ b/templates/arch/index.html @@ -0,0 +1,36 @@ +{% extends 'base.html' %} +{% block content %} +
+
+ Select Playbook and arguments +
+
+
+ +
+ +
+ +
+ +
+
+
+ + +{% endblock %} diff --git a/templates/arch/run.html.ok b/templates/arch/run.html.ok new file mode 100644 index 0000000..e8de07b --- /dev/null +++ b/templates/arch/run.html.ok @@ -0,0 +1,23 @@ + + + + + + + + Ansible Output + + +
+ + + + + diff --git a/templates/arch/run.html.old b/templates/arch/run.html.old new file mode 100644 index 0000000..5dacae7 --- /dev/null +++ b/templates/arch/run.html.old @@ -0,0 +1,37 @@ +{% extends 'base.html' %} +{% block content %} + +
+
+ Running playbook +
+
+ Command to run : ansible-playbook {{ playbook }} {{ argument }} +
+
+
+
+ Output +
+
+ Test +
+
+ + +

+
+    
+    
+    
+
+{% endblock %}
diff --git a/templates/base.html b/templates/base.html
new file mode 100644
index 0000000..9bb0d9b
--- /dev/null
+++ b/templates/base.html
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+{% block content %}{% endblock %} +
+ + + diff --git a/templates/edit_file.html b/templates/edit_file.html new file mode 100644 index 0000000..e79c7d4 --- /dev/null +++ b/templates/edit_file.html @@ -0,0 +1,11 @@ +{% extends 'base.html' %} +{% block content %} + < Back +
+
+ + + + +
+{% endblock %} diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..d8f5e46 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,48 @@ +{% extends 'base.html' %} +{% block content %} +
+
+ Select Playbook and arguments +
+
+
+ + + + + + +
+ +
+
+ +
+
+
+
+
+
+ Select Playbook to edit: +
+
+
+ + + +
+ +
+
+
+ + +{% endblock %} diff --git a/templates/run.html b/templates/run.html new file mode 100644 index 0000000..325888d --- /dev/null +++ b/templates/run.html @@ -0,0 +1,13 @@ +{% extends 'base.html' %} +{% block content %} +< Back +
+
+ Command output +
+
+
+
+
+ +{% endblock %}