-
Notifications
You must be signed in to change notification settings - Fork 0
/
playbook.yml
123 lines (109 loc) · 2.72 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
- name: Deploy project
hosts: all
vars:
ansible_python_interpreter: /usr/bin/python3
become: yes
become_user: root
become_method: sudo
gather_facts: no
tasks:
- name: Install required packages
apt:
update_cache: yes
name: "{{ packages }}"
vars:
packages:
- python3-pip
- postgresql
- postgresql-contrib
- libpq-dev
- nginx
- name: Symlink python
file:
src: /usr/bin/python3
dest: /usr/bin/python
state: link
owner: root
group: root
- name: Install python requirements
command: "pip3 install {{ item }}"
loop:
- django
- social-auth-app-django
- django-material
- gunicorn
- psycopg2-binary
- name: Enable passwordless sudo
lineinfile:
dest: /etc/sudoers
regexp: '^vagrant'
line: 'vagrant ALL=(postgres) NOPASSWD:/bin/sh'
- name: Create a PostgreSQL database user
postgresql_user:
name: vagrant
password: vagrant-secret
role_attr_flags: CREATEDB
state: present
become: yes
become_user: postgres
- name: Create a PostgreSQL database
postgresql_db:
name: coding_task
become: yes
become_user: postgres
- name: Copy nginx.conf
copy:
src: deploy/nginx.conf
dest: /etc/nginx/
owner: root
group: root
mode: 0644
- name: Copy gunicorn socket/service
copy:
src: deploy/{{ item }}
dest: /etc/systemd/system/
owner: root
group: root
mode: 0644
loop:
- gunicorn.socket
- gunicorn.service
- name: Copy gunicorn.conf
copy:
src: deploy/gunicorn.conf
dest: /etc/tmpfiles.d/
owner: root
group: root
mode: 0644
- name: Copy project
copy:
src: codingtask
dest: /home/vagrant/
owner: vagrant
group: vagrant
- name: Make manage.py executable
file:
path: /home/vagrant/codingtask/manage.py
mode: 0755
- name: Collect statics and Make migrations
command: "/home/vagrant/codingtask/manage.py {{ item }} --no-input"
become: true
become_user: vagrant
loop:
- collectstatic
- makemigrations
- migrate
- name: Enable Gunicorn
systemd:
daemon_reload: yes
name: "{{ item }}"
enabled: yes
state: started
loop:
- gunicorn.socket
- gunicorn.service
- name: Restart Nginx
systemd:
name: nginx
enabled: yes
state: restarted