Commit 677ecb99 authored by rexxnor's avatar rexxnor

added unfinished ansible playbook

parent 258968ca
......@@ -106,5 +106,9 @@ down vote
Session.vim
.netrwhist
*~
*.png
# Ansible and running secrets
secret.txt
*.retry
prepaidmatewebsite/prepaidmatewebsite/settings.py
hosts
---
- name: Install PrepaidMate system as daemon and run it
hosts: prepaidmate
become: True
tasks:
- name: Install required packages
apt:
name: [apache2, libapache2-mod-wsgi-py3, python3-venv, git, virtualenv]
state: present
update_cache: yes
- name: Clone repository
git:
repo: https://git.chaostreffbern.ch/rexxnor/prepaid-mate-website
dest: /var/www/html/ppm/
- name: Install Virtualenv and requirements.txt
pip:
requirements: /var/www/html/ppm/requirements.txt
virtualenv: /var/www/prepaidmatevenv/
virtualenv_python: python3
ignore_errors: yes
- name: Adding prepaidmate config for apache
template:
src: templates/prepaidmate.conf.j2
dest: /etc/apache2/sites-available/prepaidmate.conf
owner: root
group: root
mode: 0644
- name: Deactivate default apache2 site
file:
dest: /etc/apache2/sites-enabled/000-default.conf
state: absent
- name: Deactivate default SSL apache2 site
file:
dest: /etc/apache2/sites-enabled/default-ssl.conf
state: absent
- name: Activate apache2 site for Prepaidmate
file:
src: /etc/apache2/sites-available/prepaidmate.conf
dest: /etc/apache2/sites-enabled/prepaidmate.conf
state: link
- name: Ensuring correct file access rights for /var/www/html
file:
dest: /var/www/html/
owner: www-data
group: www-data
recurse: yes
- name: Restarting apache and enabling it
systemd:
name: apache2
state: restarted
enabled: yes
- name: Generating run secret with script
shell: bash gen_safe_secret.sh
args:
chdir: /var/www/html/ppm/prepaidmatewebsite/prepaidmatewebsite/
creates: /var/www/html/ppm/prepaidmatewebsite/prepaidmatewebsite/secret.txt
- name: Templating the django settings
template:
src: templates/settings.py.j2
dest: /var/www/html/ppm/prepaidmatewebsite/prepaidmatewebsite/settings.py
owner: www-data
group: www-data
mode: 0755
WSGIScriptAlias / /var/www/html/ppm/prepaidmatewebsite/prepaidmatewebsite/wsgi.py
WSGIPythonHome /var/www/prepaidmatevenv/
WSGIPythonPath /var/www/html/ppm/prepaidmatewebsite
WSGIDaemonProcess {{ ansible_eth0.ipv4.address }} python-home=/var/www/prepaidmatevenv/ python-path=/var/www/html/ppm/prepaidmatewebsite/
WSGIProcessGroup {{ ansible_eth0.ipv4.address }}
<VirtualHost *:80>
DocumentRoot /var/www/html
<Directory /var/www/html/ppm/prepaidmatewebsite/prepaidmatewebsite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /var/www/html/ppm/prepaidmatewebsite/prepaid/static>
Require all granted
</Directory>
</VirtualHost>
"""
Django settings for prepaidmatewebsite project.
Generated by 'django-admin startproject' using Django 1.11.1.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['{{ ansible_eth0.ipv4.address }}']
# Application definition
INSTALLED_APPS = [
'prepaid.apps.PrepaidConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'drf_generators',
'djmoney',
'coverage',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'prepaidmatewebsite.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.jinja2.Jinja2',
'DIRS': ['templates/'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True, # This allows Django to find the templates in the admin app
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'prepaidmatewebsite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'prepaid/static/')
# Security Stuff
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
CSRF_COOKIE_SECURE = True
X_FRAME_OPTIONS = "DENY"
# Needs to have TLS enabled for this!!
# SESSION_COOKIE_SECURE = True
# Secret key generated by gen_safe_secret.sh
with open(os.path.join(BASE_DIR, 'prepaidmatewebsite/secret.txt')) as f:
SECRET_KEY = f.read().strip()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment