forked from kodekloudhub/simple_web_application
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook.yml
80 lines (68 loc) · 1.81 KB
/
playbook.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# This playbook requires privilege escalation to be set. Please
# refer the ansible.cfg in current working directory for privilege_escalation
# configuration.
- name: Deploy a web application
hosts: db_and_web_server1,db_and_web_server2
tasks:
- name: Install all required dependencies
yum:
name: "{{ item }}"
state: present
with_items:
- "epel-release"
- "python"
- "python-devel"
- name: Install MySQL community repository
yum:
name: "http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm"
state: present
- name: Install MySQL database
yum:
name: "{{ item }}"
state: present
with_items:
- "mysql-server"
- "mysql-devel"
- name: create MySQL configuration file
copy:
content: |
[client]
user=root
password="@targ8et"
dest: "/etc/.my.cnf"
- name: Start MySQL Service
service:
name: mysqld
state: started
enabled: yes
- name: Install mysql-python package
yum:
name: MySQL-python
state: present
- name: Install pip
yum:
name: "python-pip"
state: present
- name: Install required Python libraries
pip:
name: "{{ item }}"
state: present
with_items:
- "flask"
- "flask-mysql"
- name: Create Application Database
mysql_db:
name: employee_db
state: present
- name: Create Database user
mysql_user:
name: db_user
password: Passw0rd
priv: '*.*:ALL'
state: present
- name: Copy source code
copy:
src: app.py
dest: /opt/app.py
- name: Start web server
shell: FLASK_APP=/opt/app.py nohup flask run --host=0.0.0.0 &