extras/ansible/roles/middleware/tasks/main.yml
---
- name: Check SSH public key
local_action: command test -e {{ ssh_public_key_file }}
register: ssh_public_key_test
ignore_errors: yes
# user
- name: Create user {{ myblog_user }}
user: name="{{ myblog_user }}" shell=/bin/bash home="{{ myblog_home }}"
# - name: Add SSH public key to {{ myblog_user }}
# authorized_key: user={{ myblog_user }}
# key="{{ lookup('file', ssh_public_key_file) }}"
# when: ssh_public_key_test.rc == 0
# myblog
- name: Install requirements
apt: name={{ item }} state=present
with_items:
- python
- python-dev
- python-setuptools
- build-essential
- libmysqlclient-dev
- libjpeg-dev
- name: Install pip
easy_install: name=pip
- name: Upgrade pip
pip: name=pip
- name: Install virtualenv
pip: name=virtualenv
- include: install_geoip.yml
- name: Install Django Python MySQL and Redis clients
pip: name={{ item }} virtualenv="{{ myblog_venv }}"
remote_user: "{{ myblog_user }}"
with_items:
- 'django<1.9'
- MySQL-python
- django-redis
- 'git+http://github.com/ojii/pymaging.git#egg=pymaging'
- 'git+http://github.com/ojii/pymaging-png.git#egg=pymaging-png'
- 'git+http://github.com/ZuluPro/django-cv#egg=django-cv'
- name: Git pull blog
git: repo=https://github.com/ZuluPro/myblog.git
dest={{ myblog_src }} version={{ myblog_version }}
remote_user: "{{ myblog_user }}"
register: git_pull_myblog
- name: Install myblog requirements
pip: requirements={{ myblog_src }}/requirements.txt
virtualenv="{{ myblog_venv }}"
remote_user: "{{ myblog_user }}"
- name: Install myblog
shell: "{{ myblog_venv }}/bin/python setup.py install"
args:
chdir: "{{ myblog_src }}"
remote_user: "{{ myblog_user }}"
when: git_pull_myblog.changed
notify: restart uwsgi
- name: Get package directory
shell: "{{ myblog_venv }}/bin/myblog settings | awk '/BASE_DIR/ {print $3}'"
remote_user: "{{ myblog_user }}"
register: myblog_basedir
changed_when: False
environment:
PATH: "{{ myblog_venv }}/bin/:{{ ansible_env.PATH }}"
- name: Setup myblog configuration
template: src=myblog.cfg.j2 dest=/etc/myblog.cfg mode=0644 owner=root
- name: Create static root directory
file: dest="{{ static_root }}" state=directory owner={{ myblog_user }} group={{ myblog_user }}
mode=0740
- name: Create media root directory
file: dest="{{ media_root }}" state=directory owner={{ myblog_user }} group={{ myblog_user }}
mode=0755
- name: Create backup directory
file: dest="{{ backup_dir }}" state=directory owner={{ myblog_user }} group={{ myblog_user }}
mode=0740
- name: Collect static files
command: "{{ myblog_venv }}/bin/myblog collectstatic --noinput"
remote_user: "{{ myblog_user }}"
register: collectstatic
run_once: true
changed_when: "not '0 static files copied to' in collectstatic.stdout"
- name: Generate favicon
command: "{{ myblog_venv }}/bin/myblog generate_favicon file://img/avatar.png --noinput"
remote_user: "{{ myblog_user }}"
- name: Generate admin favicon
command: "{{ myblog_venv }}/bin/myblog generate_favicon file://img/avatar-grey.png --prefix=admin/ --noinput"
remote_user: "{{ myblog_user }}"
- name: Deploy database
command: "{{ myblog_venv }}/bin/myblog migrate --noinput"
remote_user: "{{ myblog_user }}"
register: migration
changed_when: "not 'No migrations to apply.' in migration.stdout"
# uWSGI
# Remake with supervisord
- name: Install uWSGI
apt: name={{ item }} state=installed
with_items:
- uwsgi
- uwsgi-plugin-python
- name: Setup myblog uWSGI configuration
template: src=uwsgi.ini.j2 dest=/etc/uwsgi/apps-available/myblog.ini
notify: restart uwsgi
- name: Enable myblog uWSGI configuration
file: src=/etc/uwsgi/apps-available/myblog.ini dest=/etc/uwsgi/apps-enabled/myblog.ini state=link
# Nginx
- include: ../../common/tasks/install_nginx.yml
- include: ../../common/tasks/install_ssl_key.yml
- name: Setup media Nginx configuration
template: src=nginx-media.conf.j2 dest=/etc/nginx/sites-available/media-myblog.conf
notify: reload nginx
- name: Enable myblog Nginx configuration
file: src=/etc/nginx/sites-available/media-myblog.conf dest=/etc/nginx/sites-enabled/media-myblog.conf state=link
notify: restart nginx
- name: Create www directory
file: dest="/var/www/" state=directory owner=www-data group=www-data
mode=0744
- name: Add symlink for media files
file: src={{ media_root }} dest=/var/www/media state=link owner=www-data group=www-data