diff --git a/Vagrantfile b/Vagrantfile index 8638846..ec4967f 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -23,6 +23,8 @@ Vagrant.configure(2) do |config| # within the machine from a port on the host machine. In the example below, # accessing "localhost:8080" will access port 80 on the guest machine. config.vm.network "forwarded_port", guest: 80, host: 8080 + config.vm.network "forwarded_port", guest: 9002, host: 8000 + # Create a private network, which allows host-only access to the machine # using a specific IP. @@ -67,7 +69,7 @@ Vagrant.configure(2) do |config| ansible.playbook = "playbook.yml" ansible.host_key_checking = "False" ansible.inventory_path = "hosts" - ansible.verbose = "v" + ansible.verbose = "vvv" ansible.limit = "vagrant" end end diff --git a/playbook.yml b/playbook.yml index b909fa8..279e02c 100644 --- a/playbook.yml +++ b/playbook.yml @@ -1,6 +1,29 @@ --- - hosts: all sudo: true + gather_facts: yes roles: + - andyceo.git + - bennojoy.mysql - common + - nginx + - erasme.etherpad + + + + vars: + - etherpad_deploy_user : etherpad + - etherpad_port : 9001 + - etherpad_log_parent_dir : /var/log + - etherpad_session_key: default + - etherpad_version : master + - etherpad_path: /var/www/html + - etherpad_repos: https://github.com/ether/etherpad-lite.git + - etherpad_database: + name: etherpad + user: etherpad + host: localhost + password: etherpad + - mysql_db: [{name: etherpad}] + - mysql_users: [{name: etherpad, pass: etherpad, priv: "*.*:ALL"}] diff --git a/requirements.yml b/requirements.yml index 3e9eef9..183faea 100644 --- a/requirements.yml +++ b/requirements.yml @@ -2,3 +2,12 @@ # https://github.com/yatesr/ansible-timezone - src: yatesr.timezone + +# https://github.com/erasme/ansible-etherpad +- src: erasme.etherpad + +# https://github.com/bennojoy/mysql +- src: bennojoy.mysql + +# https://github.com/andyceo/ansible-role-git +- src: andyceo.git diff --git a/roles/nginx/handlers/main.yml b/roles/nginx/handlers/main.yml new file mode 100755 index 0000000..641767a --- /dev/null +++ b/roles/nginx/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: restart nginx + service: name=nginx state=restarted + +- name: reload nginx + service: name=nginx state=reloaded \ No newline at end of file diff --git a/roles/nginx/tasks/main.yml b/roles/nginx/tasks/main.yml new file mode 100755 index 0000000..4ce9248 --- /dev/null +++ b/roles/nginx/tasks/main.yml @@ -0,0 +1,22 @@ +--- +- name: install NGINX Server. + apt: pkg=nginx state=installed update-cache=yes + +- name: copy base nginx configuration. + template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf + notify: restart nginx + +- name: delete default vhost. + action: file path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + +- name: copy site host configuration. + template: src=site.conf.j2 dest=/etc/nginx/sites-available/{{project_name}}.conf + notify: restart nginx + +- name: put host configuration in sites-enabled + file: src=/etc/nginx/sites-available/{{project_name}}.conf dest=/etc/nginx/sites-enabled/{{project_name}} state=link + notify: restart nginx + +- name: ensure nginx is running + service: name=nginx state=started \ No newline at end of file diff --git a/roles/nginx/templates/nginx.conf.j2 b/roles/nginx/templates/nginx.conf.j2 new file mode 100755 index 0000000..c8a1478 --- /dev/null +++ b/roles/nginx/templates/nginx.conf.j2 @@ -0,0 +1,95 @@ +user www-data; +worker_processes 1; +pid /var/run/nginx.pid; + +events { + worker_connections 768; + # multi_accept on; +} + +http { + + ## + # Basic Settings + ## + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + # server_tokens off; + + # server_names_hash_bucket_size 64; + # server_name_in_redirect off; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + ## + # Logging Settings + ## + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + ## + # Gzip Settings + ## + + gzip on; + gzip_disable "msie6"; + + # gzip_vary on; + # gzip_proxied any; + # gzip_comp_level 6; + # gzip_buffers 16 8k; + # gzip_http_version 1.1; + # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; + + ## + # nginx-naxsi config + ## + # Uncomment it if you installed nginx-naxsi + ## + + #include /etc/nginx/naxsi_core.rules; + + ## + # nginx-passenger config + ## + # Uncomment it if you installed nginx-passenger + ## + + #passenger_root /usr; + #passenger_ruby /usr/bin/ruby; + + ## + # Virtual Host Configs + ## + + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-enabled/*; +} + + +#mail { +# # See sample authentication script at: +# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript +# +# # auth_http localhost/auth.php; +# # pop3_capabilities "TOP" "USER"; +# # imap_capabilities "IMAP4rev1" "UIDPLUS"; +# +# server { +# listen localhost:110; +# protocol pop3; +# proxy on; +# } +# +# server { +# listen localhost:143; +# protocol imap; +# proxy on; +# } +#} \ No newline at end of file diff --git a/roles/nginx/templates/site.conf.j2 b/roles/nginx/templates/site.conf.j2 new file mode 100755 index 0000000..d409701 --- /dev/null +++ b/roles/nginx/templates/site.conf.j2 @@ -0,0 +1,50 @@ +upstream app_server { + server 127.0.0.1:8000; +} + +server { + # From WWW to non-WWW, for all domains + server_name "~^www\.(.*)$" ; + return 301 $scheme://$1$request_uri ; +} + +# Serve static files and redirect any other request to django wsgi server +server { + listen 80; + + server_name {{ domain_name }}; + root /var/www/; + access_log /var/log/nginx/{{ domain_name }}.access.log; + error_log /var/log/nginx/{{ domain_name }}.error.log; + client_max_body_size 10M; + + gzip on; + gzip_min_length 1100; + gzip_buffers 4 8k; + gzip_types application/atom+xml application/javascript application/x-javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component text/xml; + + # expires 30d; + # expires max; + # expires modified +24h; + # expires @24h; + # expires 0; + # expires -1; + # expires epoch; + # add_header Cache-Control private; + + + # Check if a file exists at /var/www/ for the incoming request. + # If it doesn't proxy to Django wsgi server. + try_files $uri @app_server; + + # Setup named location for Django requests and handle proxy details + location @app_server { + add_header Cache-Control "no-cache, must-revalidate, max-age=0"; + + proxy_pass http://127.0.0.1:8000; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +}