From 16a854012deed327637efb0487dd0cdd9447cc67 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 25 Dec 2017 22:47:04 +0100 Subject: [PATCH] move some parts from the vagrant file into a separate script This way both vagrant and ansible can use the script --- Vagrantfile | 24 +------------------- ansible/roles/web_AI-5/tasks/setup_script.sh | 13 +++++++++++ 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index b7f26bb..a905239 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -32,29 +32,7 @@ Vagrant.configure("2") do |config| libnss-mdns libapache2-mod-wsgi-py3 python3-mysqldb python3-pip pip3 install django-extensions Pillow - - #initialize the db - mysql < /vagrant/sql/04_remove_database.sql - mysql < /vagrant/sql/01_create_database.sql - - #löschen und verlinken der HTML root damit man diese nicht manuel kopieren muss. - if ! [ -L /var/www/html ]; then - rm -rf /var/www/html - ln -s /vagrant/html /var/www/html - fi - - #Copy the apache configuration for django to the correct place - cp /vagrant/apache/000-default.conf /etc/apache2/sites-available/ - #restart the webserver - systemctl restart apache2.service - rm /vagrant/django/didgeridoo/webshop/migrations/*.py - python3 /vagrant/django/didgeridoo/manage.py makemigrations webshop - python3 /vagrant/django/didgeridoo/manage.py migrate - mysql < /vagrant/sql/02_insert_data.sql - echo "from django.contrib.auth.models import User; \ - User.objects.filter(email='admin@example.com').delete(); \ - User.objects.create_superuser('admin', 'admin@example.com', 'password')" | - python3 /vagrant/django/didgeridoo/manage.py shell + ./vagrant/ansible/roles/web_AI-5/tasks/setup_script.sh SHELL end diff --git a/ansible/roles/web_AI-5/tasks/setup_script.sh b/ansible/roles/web_AI-5/tasks/setup_script.sh index a8682d8..d9ed1c3 100755 --- a/ansible/roles/web_AI-5/tasks/setup_script.sh +++ b/ansible/roles/web_AI-5/tasks/setup_script.sh @@ -1,6 +1,19 @@ +#initialize the db mysql < /vagrant/sql/04_remove_database.sql mysql < /vagrant/sql/01_create_database.sql + +#remove old migrations rm /vagrant/django/didgeridoo/webshop/migrations/*.py + +#create and insert the new migrations python3 /vagrant/django/didgeridoo/manage.py makemigrations webshop python3 /vagrant/django/didgeridoo/manage.py migrate + +#insert some default data into the database mysql < /vagrant/sql/02_insert_data.sql + +#create an admin user +echo "from django.contrib.auth.models import User; \ + User.objects.filter(email='admin@example.com').delete(); \ + User.objects.create_superuser('admin', 'admin@example.com', 'password')" | + python3 /vagrant/django/didgeridoo/manage.py shell