Skip to content

Commit a837c72

Browse files
Improve ansible provision playbook
1 parent 92d6139 commit a837c72

File tree

4 files changed

+76
-7
lines changed

4 files changed

+76
-7
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
- name: restart nginx
3+
service: name=nginx state=restarted
4+
become_user: root
5+
6+
- name: stop nginx
7+
service: name=nginx state=stopped
8+
become_user: root
9+
10+
- name: start nginx
11+
service: name=nginx state=started
12+
become_user: root
13+
14+
- name: reload nginx
15+
service: name=nginx state=reloaded
16+
become_user: root
17+
18+
- name: restart supervisor
19+
service: name=supervisor state=restarted
20+
become_user: root
21+
22+
# - name: restart gunicorn
23+
# action: service name={{ project_name }}_gunicorn state=restarted
24+
# sudo_user: root

contrib/ansible_playbooks/provision.yml

+42
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,47 @@
3434
- name: Pull sources from the repository.
3535
git: repo={{ project_repo }} dest={{ project_root }} version={{ branch }} accept_hostkey=True force=yes
3636

37+
- name: Create virtualenv
38+
shell: /usr/bin/python3.5 -m venv {{ virtualenv_directory }}
39+
40+
- name: Install requirements of Python project.
41+
pip: requirements={{ project_root }}/requirements.txt virtualenv={{ virtualenv_directory }}
42+
43+
- name: Upload robots.txt configuration file.
44+
copy: src=secret/robots.txt dest={{ project_root }}
45+
3746
- name: Change permissions.
3847
file: dest={{ project_home }} owner={{ project_name }} group={{ project_name }} recurse=yes
48+
49+
- name: Install supervisor uwsgi configuration file.
50+
copy: src=secret/uwsgi.conf dest=/etc/supervisor/conf.d/{{ project_name }}_uwsgi.conf
51+
notify: restart supervisor
52+
53+
## Dependent tasks
54+
55+
- name: Find default configurations of nginx sites-enabled.
56+
find: paths="/etc/nginx/sites-enabled"
57+
register: result
58+
59+
- name: Remove files from sites-enabled of nginx.
60+
file: path={{ item.path }} state=absent
61+
with_items:
62+
- "{{ result.files }}"
63+
64+
##
65+
66+
- name: Upload nginx configuration file to sites-available.
67+
copy: src=secret/nginx.conf dest=/etc/nginx/sites-available/{{ project_name }}.conf
68+
69+
- name: Upload nginx configuration file to sites-enabled.
70+
copy: src=secret/nginx.conf dest=/etc/nginx/sites-enabled/{{ project_name }}.conf
71+
notify: restart nginx
72+
73+
- name: Enable supervisor on start.
74+
shell: update-rc.d supervisor defaults && update-rc.d supervisor enable
75+
76+
- name: Create database.
77+
shell: SECRET_KEY={{ secret_key }} SERVER_NAME={{ server_name }} DATABASE_URI={{ database_uri }} python db_create.py
78+
79+
handlers:
80+
- include: handlers.yml
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[program:uwsgi_flasktutorial]
2-
command=/home/flasktutorial/.venv/bin/uwsgi --master --socket=/home/flasktutorial/uwsgi.sock --chmod-socket=666 --workers=4 --pythonpath=/home/flasktutorial/project/ --wsgi=hci_api.wsgi --enable-threads --single-interpreter --stats /home/flasktutorial/uwsgistats.sock
2+
command=/home/flasktutorial/.venv/bin/uwsgi --master --socket=/home/flasktutorial/uwsgi.sock --chmod-socket=666 --workers=4 --pythonpath=/home/flasktutorial/project/ --wsgi=tvseries:create_app\(\) --enable-threads --single-interpreter --stats /home/flasktutorial/uwsgistats.sock
33
user=flasktutorial
44
numprocs=1
55
stdout_logfile=/home/flasktutorial/flasktutorial.log
66
stderr_logfile=/home/flasktutorial/flasktutorial_error.log
77
autostart=true
88
autorestart=true
99
stopsignal=QUIT
10-
environment=SECRET_KEY="<your secret key>",SERVER_NAME="<your host ip>",DATABASE_URI="sqlite:///tvseries.sqlite3"
10+
environment=SECRET_KEY="<your secret key>",SERVER_NAME="<your server name>",DATABASE_URI="sqlite:///tvseries.sqlite3"
1111

contrib/ansible_playbooks/secret/vars.yml

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ project_home: /home/flasktutorial
44
project_root: /home/flasktutorial/project
55
virtualenv_directory: /home/flasktutorial/.venv
66
project_repo: [email protected]:rafaelhenrique/flask_tutorial.git
7-
private_key_github: /home/<your local user>/.ssh/id_rsa
8-
public_key_github: /home/<your local user>/.ssh/id_rsa.pub
9-
management_user: <management user of application host>
7+
private_key_github: /home/rafael/.ssh/id_rsa
8+
public_key_github: /home/rafael/.ssh/id_rsa.pub
9+
management_user: rafael
10+
secret_key: '<your secret key>'
11+
server_name: '<your server name>'
12+
database_uri: 'sqlite:///tvseries.sqlite3'
1013
production_variables:
11-
SECRET_KEY: '<inform your secret key>'
12-
SERVER_NAME: '<inform your host>'
14+
SECRET_KEY: '<your secret key>'
15+
SERVER_NAME: '<your server name >'
1316
DATABASE_URI: 'sqlite:///tvseries.sqlite3'
1417
system_packages:
1518
- build-essential

0 commit comments

Comments
 (0)