Compare commits

..

5 Commits

Author SHA1 Message Date
Yohann D'ANELLO 4761d46696 🎨 Apply Django migrations 2020-07-15 11:32:08 +02:00
Yohann D'ANELLO 084d22d33f Install PSQL and init DB 2020-07-15 10:09:28 +02:00
Yohann D'ANELLO 3f0208a664 🐛 First fix Ansible installation 2020-07-15 09:27:11 +02:00
Yohann D'ANELLO 3dfed70eb1 💩 Use HTTPS rather than SSH to clone nk20-scripts (may be reverted later) 2020-07-15 08:25:52 +02:00
Yohann D'ANELLO cdc053718f 🚀 Adding Ansible configuration (not tested) 2020-07-15 07:46:42 +02:00
11 changed files with 163 additions and 4 deletions

View File

@ -1,4 +1,4 @@
DJANGO_APP_STAGE=dev DJANGO_APP_STAGE=prod
# Only used in dev mode, change to "postgresql" if you want to use PostgreSQL in dev # Only used in dev mode, change to "postgresql" if you want to use PostgreSQL in dev
DJANGO_DEV_STORE_METHOD=sqllite DJANGO_DEV_STORE_METHOD=sqllite
DJANGO_DB_HOST=localhost DJANGO_DB_HOST=localhost
@ -13,6 +13,6 @@ NOTE_URL=localhost
# Config for mails. Only used in production # Config for mails. Only used in production
NOTE_MAIL=notekfet@localhost NOTE_MAIL=notekfet@localhost
EMAIL_HOST=smtp.localhost EMAIL_HOST=smtp.localhost
EMAIL_PORT=443 EMAIL_PORT=465
EMAIL_USER=notekfet@localhost EMAIL_USER=notekfet@localhost
EMAIL_PASSWORD=CHANGE_ME EMAIL_PASSWORD=CHANGE_ME

2
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "apps/scripts"] [submodule "apps/scripts"]
path = apps/scripts path = apps/scripts
url = git@gitlab.crans.org:bde/nk20-scripts.git url = https://gitlab.crans.org/bde/nk20-scripts.git

View File

@ -121,7 +121,7 @@ On supposera pour la suite que vous utilisez Debian/Ubuntu sur un serveur tout n
# Le reste n'est utile qu'en production, pour configurer l'envoi des mails # Le reste n'est utile qu'en production, pour configurer l'envoi des mails
NOTE_MAIL=notekfet@localhost NOTE_MAIL=notekfet@localhost
EMAIL_HOST=smtp.localhost EMAIL_HOST=smtp.localhost
EMAIL_PORT=443 EMAIL_PORT=465
EMAIL_USER=notekfet@localhost EMAIL_USER=notekfet@localhost
EMAIL_PASSWORD=CHANGE_ME EMAIL_PASSWORD=CHANGE_ME

14
ansible/ansible.cfg Normal file
View File

@ -0,0 +1,14 @@
[defaults]
inventory = ./hosts
timeout = 42
[privilege_escalation]
become = True
become_ask_pass = True
[ssh_connection]
pipelining = True
retries = 3
[diff]
always = yes

10
ansible/base.yml Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env ansible-playbook
---
- hosts: bde-nk20-beta.adh.crans.org
roles:
- 1-apt-basic
- 2-nk20
- 3-pip
- 4-nginx
- 5-psql

5
ansible/hosts Normal file
View File

@ -0,0 +1,5 @@
[server]
bde-nk20-beta.adh.crans.org
[all:vars]
ansible_python_interpreter=/usr/bin/python3

View File

@ -0,0 +1,20 @@
---
- name: Install basic APT packages
apt:
update_cache: true
name:
- nginx
- python3
- python3-pip
- python3-dev
- uwsgi
- uwsgi-plugin-python3
- python3-venv
- git
- acl
- texlive-latex-extra
- texlive-fonts-extra
- texlive-lang-french
register: pkg_result
retries: 3
until: pkg_result is succeeded

View File

@ -0,0 +1,26 @@
---
- name: Create note_kfet dir with good permissions
file:
path: /var/www/note_kfet
state: directory
owner: www-data
group: www-data
mode: u=rwx,g=rwxs,o=rx
- name: Clone Note Kfet
git:
repo: https://gitlab.crans.org/bde/nk20.git
dest: /var/www/note_kfet
version: beta-soon
force: true
- name: Use default env vars (should be updated!)
command: cp /var/www/note_kfet/.env_example /var/www/note_kfet/.env
- name: Update permissions for note_kfet dir
file:
path: /var/www/note_kfet
state: directory
recurse: yes
owner: www-data
group: www-data

View File

@ -0,0 +1,14 @@
---
- name: Install PIP basic dependencies
pip:
requirements: /var/www/note_kfet/requirements/base.txt
virtualenv: /var/www/note_kfet/env
virtualenv_command: /usr/bin/python3 -m venv
become_user: www-data
- name: Install PIP production dependencies
pip:
requirements: /var/www/note_kfet/requirements/production.txt
virtualenv: /var/www/note_kfet/env
virtualenv_command: /usr/bin/python3 -m venv
become_user: www-data

View File

@ -0,0 +1,31 @@
---
- name: Copy example conf of Nginx
command: cp /var/www/note_kfet/nginx_note.conf_example /var/www/note_kfet/nginx_note.conf
- name: Update Nginx conf
replace:
path: /var/www/note_kfet/nginx_note.conf
regexp: 'note.example.org'
replace: 'bde-nk20-beta.adh.crans.org'
- name: Copy conf to Nginx
file:
src: /var/www/note_kfet/nginx_note.conf
dest: /etc/nginx/sites-enabled/nginx_note.conf
state: link
- name: Copy conf to UWSGI
file:
src: /var/www/note_kfet/uwsgi_note.ini
dest: /etc/uwsgi/apps-enabled/uwsgi_note.ini
state: link
- name: Reload Nginx
systemd:
name: nginx
state: reloaded
- name: Restart UWSGI
systemd:
name: uwsgi
state: restarted

View File

@ -0,0 +1,39 @@
---
- name: Install PostgreSQL APT packages
apt:
update_cache: true
name:
- postgresql
- postgresql-contrib
- libpq-dev
register: pkg_result
retries: 3
until: pkg_result is succeeded
- name: Install Psycopg2
pip:
name: psycopg2-binary
- name: Create role note
postgresql_user:
name: note
password: "CHANGE_ME"
become_user: postgres
- name: Create NK20 database
postgresql_db:
name: note_db
owner: note
become_user: postgres
- name: Make Django migrations
command: /var/www/note_kfet/env/bin/python manage.py makemigrations
args:
chdir: /var/www/note_kfet
become_user: www-data
- name: Migrate Django database
command: /var/www/note_kfet/env/bin/python manage.py migrate
args:
chdir: /var/www/note_kfet
become_user: www-data