-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebapp_playbook.yml
93 lines (87 loc) · 2.5 KB
/
webapp_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
81
82
83
84
85
86
87
88
89
90
91
92
93
# Ansible playbook for deploying a Flask app
---
# Install system apt packages
- hosts: webservers
become: yes
become_method: sudo
tasks:
- name: update
apt: update_cache=yes
- name: install packages
apt: name={{item}} state=present
with_items:
- python3
- python3-pip
- python3-venv
- python3-dev
- nginx
# Install the app, note: don't do these tasks with become sudo
- hosts: webservers
tasks:
- name: clone repo
git:
repo: 'https://github.com/{{ github_user }}/{{ app_name }}.git'
dest: /home/{{ ansible_ssh_user }}/{{ app_name }}
update: yes # Does a git pull if the repo already exists
- name: Install virtualenv via pip
pip:
name: virtualenv
executable: pip3
- name: install modules in a virtualenv
pip:
requirements: /home/devops/BestFW/requirements.txt
virtualenv: /home/devops/BestFW/venv
virtualenv_python: python3.8.10
tags:
-venv
environment:
PATH: "{{ ansible_env.PATH }}:{{ ansible_user_dir }}/.local/bin"
# Configure app systemd service and nginx
- hosts: webservers
become: yes
become_method: sudo
tasks:
- name: template systemd service config
copy:
src: bestfw.service
dest: /etc/systemd/system/bestfw.service
- name: remove nginx.conf
file: path=/etc/nginx/nginx.conf state=absent
- name: copy ngnix configuration
copy:
src: nginx.conf
dest: /etc/nginx
- name: start systemd app service
systemd: name=bestfw.service state=restarted enabled=yes
- name: template nginx site config
template:
src: default
dest: /etc/nginx/sites-available/default
- name: remove default nginx site config
file: path=/etc/nginx/sites-enabled/default state=absent
# - command: mv /etc/nginx/sites-enabled/default /tmp/nginx.sites-enabled.default
- name: enable nginx site
file:
src: /etc/nginx/sites-available/default
dest: /etc/nginx/sites-enabled/default
state: link
force: yes
- name: restart nginx
systemd: name=nginx state=restarted enabled=yes
- name: open firewall for nginx
ufw:
rule: allow
name: Nginx Full
# Run a quick test to verify the site is working
- hosts: webservers
tasks:
- name: get url
get_url:
url: http://{{inventory_hostname}}
dest: /tmp/index.html
- name: read html
shell: cat /tmp/index.html
register: html_contents
- name: check for string in html
when: html_contents.stdout.find('hello') != -1
debug: msg="success!"