Skip to content

Instantly share code, notes, and snippets.

@ostcar
Created May 10, 2016 22:49
Show Gist options
  • Save ostcar/05140c0d90bf787bfe7814194b609f09 to your computer and use it in GitHub Desktop.
Save ostcar/05140c0d90bf787bfe7814194b609f09 to your computer and use it in GitHub Desktop.
Create openslides inside ubuntu 16.04
---
- hosts: openslides
become: yes
vars:
settings_path: /etc/openslides
user_data_path: /usr/local/lib/openslides
secure_key: 'MakeMeRANDOM'
domain: openslides.oshahn.de
tasks:
- name: Activate universe sources
copy:
dest: /etc/apt/sources.list
content: |
deb http://archive.ubuntu.com/ubuntu xenial main universe
- name: Update System
apt:
update_cache: yes
upgrade: dist
cache_valid_time: 3600
- name: Install packages
apt:
name: "{{ item }}"
with_items:
- nginx
- python3-bs4
- python3-djangorestframework
- python3-html5lib
- python3-django-jsonfield
- python3-natsort
- python3-reportlab
- python3-roman
- python3-setuptools
- python3-sockjs-tornado
- python3-whoosh
- python3-pypdf2
- python3-pip
- name: Create user openslides
user:
name: openslides
system: yes
createhome: no
- name: Install openslides via pip
pip:
name: openslides
executable: pip3
- name: Create settings path
file:
path: "{{ settings_path }}"
state: directory
mode: 0755
- name: create user data path
file:
path: "{{ user_data_path }}"
state: directory
mode: 0755
owner: openslides
- name: Create Settings
copy:
dest: "{{ settings_path }}/settings.py"
content: |
from openslides.global_settings import *
SECRET_KEY = '{{ secure_key }}'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '{{ user_data_path }}/database.sqlite',
}
}
MEDIA_ROOT = '{{ user_data_path }}/media/'
SEARCH_INDEX = '{{ user_data_path }}/search_index/'
STATIC_ROOT = '{{ user_data_path }}/collected_static/'
- name: Migrate Database
command: openslides migrate --pythonpath {{ settings_path }} --settings settings --noinput
args:
creates: "{{ user_data_path }}/database.sqlite"
become_user: openslides
- name: Collect Static
command: openslides collectstatic --pythonpath {{ settings_path }} --settings settings --noinput
args:
creates: "{{ user_data_path }}/collected_static/css"
become_user: openslides
# The unit should be shipped with openslides
- name: Copy systemd-unit for openslides
copy:
dest: /etc/systemd/system/openslides.service
content: |
[Unit]
Description=Presentation and assembly system
Wants=network.target
[Service]
ExecStart=/usr/local/bin/openslides runserver 0.0.0.0:8400 --pythonpath /etc/openslides --settings settings
User=openslides
[Install]
WantedBy=multi-user.target
register: createOpenslidesSystemFile
- name: Reload systemd units
command: systemctl daemon-reload
when: createOpenslidesSystemFile.changed
- name: Start and enalbe openslides
service:
name: openslides
enabled: yes
state: started
- name: Create nginx config
copy:
dest: "/etc/nginx/sites-enabled/openslides"
content: |
server {
server_name {{ domain }};
listen 0.0.0.0:80;
listen [::]:80;
location /static/ {
alias {{ user_data_path }}/collected_static/;
}
location /media/ {
alias {{ user_data_path }}/media/;
}
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://localhost:8400;
}
}
notify:
- Restart nginx
handlers:
- name: Restart nginx
service:
name: nginx
state: restarted
@johnfelipe
Copy link

How can this in ubuntu 14.04

i run my instance

cd OpenSlides
screen -S OPENSLIDE
source .virtualenv/bin/activate
python manage.py runserver 0.0.0.0:8001

@ostcar
Copy link
Author

ostcar commented May 26, 2016

This ansible script can not run in ubuntu 14.04, because ubuntu 14.04 does not bring the necessary dependencies and does not run with systemd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment