From 57e64c9cfabf70c668758831dba5beb7093a6b8f Mon Sep 17 00:00:00 2001 From: Adam Dobrawy Date: Tue, 21 Mar 2017 09:23:01 +0100 Subject: [PATCH] Initial Vagrant and Ansible provision --- Vagrantfile | 31 ++++++++++++++++ vagrant_provision_ansible.yaml | 67 ++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 Vagrantfile create mode 100644 vagrant_provision_ansible.yaml diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 000000000..3b12e0a85 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,31 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. + +#!/usr/bin/env bash + +Vagrant.configure("2") do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://atlas.hashicorp.com/search. + config.vm.box = "bento/ubuntu-16.04" + + config.vm.define "mgmt" do |web| + web.vm.network "private_network", ip: "192.168.33.10" + web.vm.network :forwarded_port, guest: 22, host: 2210 + web.vm.provider "virxtualbox" do |vb| + vb.memory = 1024 + end + web.vm.provision :ansible do |ansible| + ansible.playbook = "vagrant_provision_ansible.yaml" + end + end + +end diff --git a/vagrant_provision_ansible.yaml b/vagrant_provision_ansible.yaml new file mode 100644 index 000000000..6b056ce82 --- /dev/null +++ b/vagrant_provision_ansible.yaml @@ -0,0 +1,67 @@ +--- +- hosts: all + become: yes + become_user: root + vars: + db_name: feder + db_user: feder + db_pass: feder + settings: { + DJANGO_SETTINGS_MODULE: "config.local", + DATABASE_URL: "mysql://{{db_user}}:{{db_pass}}@localhost/{{db_name}}" + } + tasks: + - name: Install OS-level libraries and application + apt: + name: "{{item}}" + state: latest + with_items: + - python2.7 + - mariadb-server + - git + - libmariadb-client-lgpl-dev + - virtualenv + - python-dev + - libffi-dev + - libssl-dev + - libjpeg-dev + - libpng12-dev + - libxml2-dev + - libxslt1-dev + - build-essential + - libjpeg62 + - name: Install OS-level Python dependencies + pip: name={{item}} state=present + with_items: + - pip + - wheel + + - name: Create a new MariaDB database + mysql_db: + name: "{{ db_name }}" + state: "present" + + - name: Create a new MariaDB user + mysql_user: + name: "{{ db_user }}" + password: "{{ db_pass }}" + host: "%" + priv: '{{ db_name }}.*:ALL' + state: present + + - name: Create virtualenv + pip: + requirements: "/vagrant/requirements/local.txt" + virtualenv: "env" + + - name: execute database migrations + django_manage: command=migrate + app_path=/vagrant + virtualenv=env + environment: "{{ settings }}" + + - name: execute collectstatic + django_manage: command=collectstatic + app_path=/vagrant + virtualenv=env + environment: "{{ settings }}"