Commit 9a5b352a authored by rexxnor's avatar rexxnor

updated requirements and added database playbook

parent d7b03ca9
---
- name: Install MariaDB on target and create Database
hosts: prepaidmatedb
become: True
tasks:
- name: Install required packages
apt:
name: [mariadb-server, python3-mysqldb]
state: present
update_cache: yes
- name: Starting mariadb-server and enabling it
systemd:
name: mariadb
state: started
enabled: yes
- name: Creating prepaidmate database
mysql_db:
name: prepaidmate
state: present
- name: Create database password using command from gen_safe_secret.sh
shell: "head /dev/urandom | tr -dc A-Za-z0-9 | head -c 64"
register: dbreturn
- name: Register the database password
set_fact:
dbpassword: "{{ dbreturn.stdout }}"
- name: Creating database users and granting rights
mysql_user:
name: ppm
password: "{{ dbpassword }}"
priv: 'prepaidmate.*:ALL'
state: present
- name: Create .my.cnf file that is used in settings.py
template:
src: templates/my.cnf.j2
dest: /var/www/prepaidmatevenv/.my.cnf
owner: www-data
group: www-data
mode: 0600
- 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
- name: Django - Collect static files for admin interface
django_manage:
virtualenv: /var/www/prepaidmatevenv/
command: collectstatic
app_path: /var/www/html/ppm/prepaidmatewebsite/
- name: Django - Create database by migrations
django_manage:
virtualenv: /var/www/prepaidmatevenv/
command: migrate
app_path: /var/www/html/ppm/prepaidmatewebsite/
- name: Restarting apache and enabling it
systemd:
name: apache2
state: reloaded
enabled: yes
[client]
database = prepaidmate
user = ppm
password = {{ dbpassword }}
default-character-set = utf8
......@@ -87,12 +87,24 @@ WSGI_APPLICATION = 'prepaidmatewebsite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
{% if (dbpassword is defined) and dbpassword %}
DATABASES = {
'default': {
'NAME': 'prepaidmate',
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': '/var/www/prepaidmatevenv/.my.cnf',
},
}
}
{% else %}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
{% endif %}
# Password validation
......
......@@ -7,6 +7,7 @@ djangorestframework==3.9.0
drf-generators==0.3.0
Jinja2==2.10
MarkupSafe==1.1.0
mysqlclient==1.3.13
py-moneyed==0.7.0
pytz==2018.7
six==1.11.0
......
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