Skip to content

Commit 8387a53

Browse files
author
Daniel Gräber
committed
Replace vagrant shell provisioning with ansible
1 parent 0d55dad commit 8387a53

File tree

7 files changed

+176
-44
lines changed

7 files changed

+176
-44
lines changed

Vagrantfile

+16-41
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
# This is the Vagrant config file for setting up an environment for Isso development.
55
# It requires:
66
#
7-
# * Vagrant (http://vagrantup.com)
8-
# * A VM engine, like VirtualBox (http://virtualbox.org)
7+
# * Vagrant (https://vagrantup.com)
8+
# * A VM engine, like VirtualBox (https://virtualbox.org)
99
# * The Vagrant-Hostmanager plugin (https://github.com/smdahlen/vagrant-hostmanager)
10+
# * Ansible (https://www.ansible.com)
1011
#
1112
# With them installed, cd into this directory and do 'vagrant up'. It's possible Vagrant will
1213
# ask for your root password so it can update your /etc/hosts file. Once it's happily churning out
@@ -17,47 +18,17 @@
1718
# to get into the VM. Useful info about it:
1819
#
1920
# * Running Ubuntu 14.04
20-
# * Isso is running on uWSGI via port 8080
21-
# * Actual webserver is Apache2, using mod_proxy_uwsgi to talk to uWSGI
22-
# * uWSGI log file is /tmp/uwsgi.log
23-
# * Isso DB file is /tmp/isso/comments.db
24-
# * Isso log file is /tmp/isso/isso.log
21+
# * Isso is running on uWSGI
22+
# * Actual webserver is Nginx to talk to uWSGI over a unix socket
23+
# * uWSGI log file is /var/log/uwsgi/apps/isso.log
24+
# * Isso DB file is /var/isso/comments.db
25+
# * Isso log file is /var/log/isso.log
26+
#
27+
# When the VM is getting rebooted vagrant mounts the shared folder after uWSGI is getting startet. To fix this issue for
28+
# the moment you need to 'vagrant ssh' into the VM and execute 'sudo service uwsgi restart'.
2529
#
2630
# Enjoy!
2731

28-
$bootstrap = <<BOOTSTRAP
29-
apt-get update
30-
apt-get install -y apache2 curl build-essential python-setuptools python-dev sqlite3 git python-pip
31-
a2enmod proxy
32-
service apache2 restart
33-
34-
curl -sL https://deb.nodesource.com/setup | bash -
35-
apt-get install -y nodejs
36-
37-
npm install -g bower requirejs uglify-js jade
38-
39-
cd /vagrant
40-
python setup.py develop
41-
make init
42-
make js
43-
44-
ln -s /vagrant/isso/demo /var/www/isso
45-
46-
pip install uwsgi
47-
mkdir -p /tmp/isso/spool
48-
49-
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
50-
chmod a+r /tmp/uwsgi.log
51-
52-
apt-get install libapache2-mod-proxy-uwsgi
53-
54-
cp /vagrant/share/isso-dev.local.apache-conf /etc/apache2/sites-available/isso-dev.local.conf
55-
a2ensite isso-dev.local
56-
a2dissite 000-default
57-
service apache2 restart
58-
59-
BOOTSTRAP
60-
6132
Vagrant.configure(2) do |config|
6233

6334
# The most common configuration options are documented and commented below.
@@ -81,7 +52,11 @@ Vagrant.configure(2) do |config|
8152
(ip = /inet addr:(\d+\.\d+\.\d+\.\d)/.match(result)) && ip[1]
8253
end
8354

84-
config.vm.provision "shell", inline: $bootstrap
55+
config.vm.provision "ansible" do |ansible|
56+
ansible.playbook = "ansible/site.yml"
57+
ansible.limit = "all"
58+
ansible.verbose = "v"
59+
end
8560

8661
config.vm.post_up_message = "Browse to http://isso-dev.local/demo/index.html to start."
8762
end

share/isso-dev.local.apache-conf ansible/files/apache.conf

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
CustomLog ${APACHE_LOG_DIR}/access.log combined
99

1010
ProxyPass / uwsgi://127.0.0.1:8080/
11-
1211
</VirtualHost>
1312

1413
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

ansible/files/nginx.conf

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
user root;
2+
worker_processes 4;
3+
worker_rlimit_nofile 8192;
4+
5+
error_log /var/log/nginx/error.log warn;
6+
pid /run/nginx.pid;
7+
8+
events {
9+
worker_connections 2014;
10+
multi_accept on;
11+
use epoll;
12+
}
13+
14+
http {
15+
include /etc/nginx/mime.types;
16+
default_type application/octet-stream;
17+
18+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
19+
'$status $body_bytes_sent "$http_referer" '
20+
'"$http_user_agent" "$http_x_forwarded_for"';
21+
22+
log_format timed '$remote_addr - $remote_user [$time_local] "$request" '
23+
'$status $body_bytes_sent "$http_referer" '
24+
'"$http_user_agent" "$http_x_forwarded_for" '
25+
'$request_time $upstream_response_time $upstream_addr '
26+
' $upstream_status $upstream_cache_status $pipe';
27+
28+
access_log /var/log/nginx/access.log timed;
29+
30+
sendfile on;
31+
tcp_nopush on;
32+
33+
keepalive_timeout 30;
34+
35+
gzip on;
36+
37+
include /etc/nginx/conf.d/*.conf;
38+
include /etc/nginx/sites-enabled/*;
39+
}

ansible/files/nginx.vhost.conf

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
server {
2+
client_max_body_size 20M;
3+
listen 80 default_server;
4+
server_name isso-dev.local;
5+
6+
root /vagrant/isso/demo;
7+
8+
location / {
9+
uwsgi_pass unix:///run/uwsgi/app/isso/socket;
10+
include uwsgi_params;
11+
}
12+
}

ansible/files/uwsgi.ini

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[uwsgi]
2+
plugins = python
3+
4+
venv = /home/vagrant/virtualenv
5+
chdir = /vagrant
6+
7+
uid = root
8+
gid = root
9+
10+
master = true
11+
processes = 4
12+
cache2 = name=hash,items=10240,blocksize=32
13+
spooler = /var/isso/spool
14+
module = isso.run
15+
env = ISSO_SETTINGS=/vagrant/share/isso-dev.conf
16+
env = PYTHON_EGG_CACHE=/tmp
17+
18+
daemonize = /var/log/uwsgi/uwsgi.log
19+
py-autoreload = 1

ansible/site.yml

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
3+
- name: Provision development server
4+
hosts: all
5+
sudo: true
6+
tasks:
7+
8+
- name: Apt | Add nodesource keys
9+
apt_key: url=https://deb.nodesource.com/gpgkey/nodesource.gpg.key state=present
10+
11+
- name: Apt | Add nodesource sources list deb
12+
apt_repository: repo='deb https://deb.nodesource.com/node {{ ansible_distribution_release }} main' state=present
13+
14+
- name: Apt | Add nodesource sources list deb src
15+
apt_repository: repo='deb-src https://deb.nodesource.com/node {{ ansible_distribution_release }} main' state=present
16+
17+
- name: Apt | Install packages
18+
apt: pkg={{ item }} state=latest update_cache=true
19+
with_items:
20+
- build-essential
21+
- curl
22+
- htop
23+
- vim
24+
- git
25+
- python-dev
26+
- python-software-properties
27+
- python-setuptools
28+
- python-virtualenv
29+
- python-pip
30+
- nginx
31+
- uwsgi
32+
- uwsgi-plugin-python
33+
- supervisor
34+
- sqlite3
35+
- nodejs
36+
37+
- name: NPM | Install packages
38+
npm: name={{ item }} global=yes
39+
with_items:
40+
- bower
41+
- requirejs
42+
- uglify-js
43+
- jade
44+
45+
- name: Virtualenv | Create
46+
shell: virtualenv "/home/vagrant/virtualenv" creates="/vagrant/virtualenv/bin/activate"
47+
48+
- name: Virtualenv | Install python egg
49+
shell: /home/vagrant/virtualenv/bin/python /vagrant/setup.py develop
50+
51+
- name: Make
52+
shell: cd /vagrant; {{ item }}
53+
with_items:
54+
- make init
55+
- make js
56+
57+
- name: Spool | Create directory
58+
file: path=/var/isso/spool state=directory mode=0777
59+
60+
- name: uwsgi | Deploy configuration
61+
copy: src=files/uwsgi.ini dest=/etc/uwsgi/apps-available/isso.ini
62+
63+
- name: uwsgi | Enable app
64+
file: src=/etc/uwsgi/apps-available/isso.ini dest=/etc/uwsgi/apps-enabled/isso.ini state=link
65+
66+
- name: uwsgi | Restart service daemon
67+
service: name=uwsgi state=restarted enabled=yes
68+
69+
- name: uwsgi | Chmod logfile
70+
file: path=/var/log/uwsgi/uwsgi.log state=touch mode="a+r"
71+
72+
- name: nginx | Deploy nginx.conf
73+
copy: src=files/nginx.conf dest=/etc/nginx/nginx.conf
74+
75+
- name: nginx | Delete default vhost
76+
action: file path=/etc/nginx/sites-enabled/default state=absent
77+
78+
- name: nginx | Deploy vhost config
79+
copy: src=files/nginx.vhost.conf dest=/etc/nginx/sites-available/isso.conf
80+
81+
- name: nginx | Enable vhost
82+
file: src=/etc/nginx/sites-available/isso.conf dest=/etc/nginx/sites-enabled/000-isso state=link
83+
84+
- name: nginx | Chmod logfile
85+
file: path=/var/log/nginx mode="a+rx" state=directory recurse=true
86+
87+
- name: nginx | Restart service daemon
88+
service: name=nginx state=restarted enabled=yes

share/isso-dev.conf

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
[general]
77

8-
dbpath = /tmp/isso/comments.db
8+
dbpath = /var/isso/comments.db
99
host = http://isso-dev.local/
1010
max-age = 15m
1111
notify = stdout
12-
log-file = /tmp/isso/isso.log
12+
log-file = /var/log/isso.log
1313

1414
[moderation]
1515
enabled = false

0 commit comments

Comments
 (0)