This is a simple web application using Python Flask and MySQL database. This is used in the demonstration of development of Ansible Playbooks.
Below are the steps required to get this working on a base linux system.
- Install all required dependencies
- Install and Configure Database
- Start Database Service
- Install and Configure Web Server
- Start Web Server
Python and its dependencies
apt-get install -y python python-setuptools python-dev build-essential python-pip python-mysqldb
Install MySQL database
apt-get install -y mysql-server mysql-client
-
Start the database service
service mysql start
-
Create database and database users
# mysql -u <username> -p mysql> CREATE DATABASE employee_db; mysql> GRANT ALL ON *.* to db_user@'%' IDENTIFIED BY 'Passw0rd'; mysql> USE employee_db; mysql> CREATE TABLE employees (name VARCHAR(20));
-
Insert some test data
mysql> INSERT INTO employees VALUES ('JOHN');
Install Python Flask dependency
pip install flask
pip install flask-mysql
- Copy app.py or download it from source repository
- Configure database credentials and parameters
Start web server
FLASK_APP=app.py flask run --host=0.0.0.0
Open a browser and go to URL
http:https://<IP>:5000 => Welcome
http:https://<IP>:5000/how%20are%20you => I am good, how about you?
http:https://<IP>:5000/read%20from%20database => JOHN