Replace vagrant shell provisioning with ansible

This commit is contained in:
Daniel Gräber 2015-02-19 13:21:57 +01:00
parent 0d55dadf46
commit 8387a5390f
7 changed files with 176 additions and 44 deletions

57
Vagrantfile vendored
View File

@ -4,9 +4,10 @@
# This is the Vagrant config file for setting up an environment for Isso development. # This is the Vagrant config file for setting up an environment for Isso development.
# It requires: # It requires:
# #
# * Vagrant (http://vagrantup.com) # * Vagrant (https://vagrantup.com)
# * A VM engine, like VirtualBox (http://virtualbox.org) # * A VM engine, like VirtualBox (https://virtualbox.org)
# * The Vagrant-Hostmanager plugin (https://github.com/smdahlen/vagrant-hostmanager) # * The Vagrant-Hostmanager plugin (https://github.com/smdahlen/vagrant-hostmanager)
# * Ansible (https://www.ansible.com)
# #
# With them installed, cd into this directory and do 'vagrant up'. It's possible Vagrant will # With them installed, cd into this directory and do 'vagrant up'. It's possible Vagrant will
# ask for your root password so it can update your /etc/hosts file. Once it's happily churning out # ask for your root password so it can update your /etc/hosts file. Once it's happily churning out
@ -17,47 +18,17 @@
# to get into the VM. Useful info about it: # to get into the VM. Useful info about it:
# #
# * Running Ubuntu 14.04 # * Running Ubuntu 14.04
# * Isso is running on uWSGI via port 8080 # * Isso is running on uWSGI
# * Actual webserver is Apache2, using mod_proxy_uwsgi to talk to uWSGI # * Actual webserver is Nginx to talk to uWSGI over a unix socket
# * uWSGI log file is /tmp/uwsgi.log # * uWSGI log file is /var/log/uwsgi/apps/isso.log
# * Isso DB file is /tmp/isso/comments.db # * Isso DB file is /var/isso/comments.db
# * Isso log file is /tmp/isso/isso.log # * Isso log file is /var/log/isso.log
#
# When the VM is getting rebooted vagrant mounts the shared folder after uWSGI is getting startet. To fix this issue for
# the moment you need to 'vagrant ssh' into the VM and execute 'sudo service uwsgi restart'.
# #
# Enjoy! # Enjoy!
$bootstrap = <<BOOTSTRAP
apt-get update
apt-get install -y apache2 curl build-essential python-setuptools python-dev sqlite3 git python-pip
a2enmod proxy
service apache2 restart
curl -sL https://deb.nodesource.com/setup | bash -
apt-get install -y nodejs
npm install -g bower requirejs uglify-js jade
cd /vagrant
python setup.py develop
make init
make js
ln -s /vagrant/isso/demo /var/www/isso
pip install uwsgi
mkdir -p /tmp/isso/spool
uwsgi --socket 127.0.0.1:8080 --master --processes 4 --cache2 name=hash,items=1024,blocksize=32 --spooler /tmp/isso/spool --module isso.run --env ISSO_SETTINGS=/vagrant/share/isso-dev.conf --daemonize /tmp/uwsgi.log --py-autoreload 1
chmod a+r /tmp/uwsgi.log
apt-get install libapache2-mod-proxy-uwsgi
cp /vagrant/share/isso-dev.local.apache-conf /etc/apache2/sites-available/isso-dev.local.conf
a2ensite isso-dev.local
a2dissite 000-default
service apache2 restart
BOOTSTRAP
Vagrant.configure(2) do |config| Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below. # The most common configuration options are documented and commented below.
@ -81,7 +52,11 @@ Vagrant.configure(2) do |config|
(ip = /inet addr:(\d+\.\d+\.\d+\.\d)/.match(result)) && ip[1] (ip = /inet addr:(\d+\.\d+\.\d+\.\d)/.match(result)) && ip[1]
end end
config.vm.provision "shell", inline: $bootstrap config.vm.provision "ansible" do |ansible|
ansible.playbook = "ansible/site.yml"
ansible.limit = "all"
ansible.verbose = "v"
end
config.vm.post_up_message = "Browse to http://isso-dev.local/demo/index.html to start." config.vm.post_up_message = "Browse to http://isso-dev.local/demo/index.html to start."
end end

View File

@ -8,7 +8,6 @@
CustomLog ${APACHE_LOG_DIR}/access.log combined CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass / uwsgi://127.0.0.1:8080/ ProxyPass / uwsgi://127.0.0.1:8080/
</VirtualHost> </VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

39
ansible/files/nginx.conf Normal file
View File

@ -0,0 +1,39 @@
user root;
worker_processes 4;
worker_rlimit_nofile 8192;
error_log /var/log/nginx/error.log warn;
pid /run/nginx.pid;
events {
worker_connections 2014;
multi_accept on;
use epoll;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format timed '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'$request_time $upstream_response_time $upstream_addr '
' $upstream_status $upstream_cache_status $pipe';
access_log /var/log/nginx/access.log timed;
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

View File

@ -0,0 +1,12 @@
server {
client_max_body_size 20M;
listen 80 default_server;
server_name isso-dev.local;
root /vagrant/isso/demo;
location / {
uwsgi_pass unix:///run/uwsgi/app/isso/socket;
include uwsgi_params;
}
}

19
ansible/files/uwsgi.ini Normal file
View File

@ -0,0 +1,19 @@
[uwsgi]
plugins = python
venv = /home/vagrant/virtualenv
chdir = /vagrant
uid = root
gid = root
master = true
processes = 4
cache2 = name=hash,items=10240,blocksize=32
spooler = /var/isso/spool
module = isso.run
env = ISSO_SETTINGS=/vagrant/share/isso-dev.conf
env = PYTHON_EGG_CACHE=/tmp
daemonize = /var/log/uwsgi/uwsgi.log
py-autoreload = 1

88
ansible/site.yml Normal file
View File

@ -0,0 +1,88 @@
---
- name: Provision development server
hosts: all
sudo: true
tasks:
- name: Apt | Add nodesource keys
apt_key: url=https://deb.nodesource.com/gpgkey/nodesource.gpg.key state=present
- name: Apt | Add nodesource sources list deb
apt_repository: repo='deb https://deb.nodesource.com/node {{ ansible_distribution_release }} main' state=present
- name: Apt | Add nodesource sources list deb src
apt_repository: repo='deb-src https://deb.nodesource.com/node {{ ansible_distribution_release }} main' state=present
- name: Apt | Install packages
apt: pkg={{ item }} state=latest update_cache=true
with_items:
- build-essential
- curl
- htop
- vim
- git
- python-dev
- python-software-properties
- python-setuptools
- python-virtualenv
- python-pip
- nginx
- uwsgi
- uwsgi-plugin-python
- supervisor
- sqlite3
- nodejs
- name: NPM | Install packages
npm: name={{ item }} global=yes
with_items:
- bower
- requirejs
- uglify-js
- jade
- name: Virtualenv | Create
shell: virtualenv "/home/vagrant/virtualenv" creates="/vagrant/virtualenv/bin/activate"
- name: Virtualenv | Install python egg
shell: /home/vagrant/virtualenv/bin/python /vagrant/setup.py develop
- name: Make
shell: cd /vagrant; {{ item }}
with_items:
- make init
- make js
- name: Spool | Create directory
file: path=/var/isso/spool state=directory mode=0777
- name: uwsgi | Deploy configuration
copy: src=files/uwsgi.ini dest=/etc/uwsgi/apps-available/isso.ini
- name: uwsgi | Enable app
file: src=/etc/uwsgi/apps-available/isso.ini dest=/etc/uwsgi/apps-enabled/isso.ini state=link
- name: uwsgi | Restart service daemon
service: name=uwsgi state=restarted enabled=yes
- name: uwsgi | Chmod logfile
file: path=/var/log/uwsgi/uwsgi.log state=touch mode="a+r"
- name: nginx | Deploy nginx.conf
copy: src=files/nginx.conf dest=/etc/nginx/nginx.conf
- name: nginx | Delete default vhost
action: file path=/etc/nginx/sites-enabled/default state=absent
- name: nginx | Deploy vhost config
copy: src=files/nginx.vhost.conf dest=/etc/nginx/sites-available/isso.conf
- name: nginx | Enable vhost
file: src=/etc/nginx/sites-available/isso.conf dest=/etc/nginx/sites-enabled/000-isso state=link
- name: nginx | Chmod logfile
file: path=/var/log/nginx mode="a+rx" state=directory recurse=true
- name: nginx | Restart service daemon
service: name=nginx state=restarted enabled=yes

View File

@ -5,11 +5,11 @@
[general] [general]
dbpath = /tmp/isso/comments.db dbpath = /var/isso/comments.db
host = http://isso-dev.local/ host = http://isso-dev.local/
max-age = 15m max-age = 15m
notify = stdout notify = stdout
log-file = /tmp/isso/isso.log log-file = /var/log/isso.log
[moderation] [moderation]
enabled = false enabled = false