publik-devinst/roles/app-setup/tasks/main.yml

172 lines
4.3 KiB
YAML

- name: set ansible server variables
set_fact:
app_settings: "{{publik_settings}}/{{project_name}}/settings.py"
app_settings_dir: "{{publik_settings}}/{{project_name}}"
manage_app_bin: "{{virtualenv}}/bin/{{project_name}}-manage"
server_app_name: "{{project_name}}"
- name: "{{app_name}} - create db"
postgresql_db:
name: "{{db_name}}"
owner: "{{user}}"
port: "{{postgresql_port}}"
become: yes
become_user: postgres
- name: "{{app_name}} - /var/lib directory"
file:
path: "{{state_dir}}"
state: directory
owner: "{{user}}"
group: "{{user}}"
become: yes
- name: "{{app_name}} - /var/lib tenants directory"
file:
path: "{{tenants_dir}}"
state: directory
owner: "{{user}}"
group: "{{user}}"
become: yes
- name: "{{app_name}} - /etc directory"
file:
path: "/etc/{{project_name}}"
state: directory
become: yes
- name: "{{app_name}} - secret file"
file:
path: "/etc/{{project_name}}/secret"
state: touch
become: yes
# FIXME : can't get a nice /dev/urandom thing working
- name: "{{app_name}} - generate secret"
shell: "echo secret > /etc/{{project_name}}/secret"
args:
executable: /bin/bash
become: yes
- name: "settings directory"
file:
path: "{{app_settings_dir}}"
state: directory
owner: "{{user}}"
group: "{{user}}"
- name: "settings.d directory"
file:
path: "{{app_settings_dir}}/settings.d"
state: directory
owner: "{{user}}"
group: "{{user}}"
- name: "{{app_name}} - settings file"
template:
src: "{{app_name}}-settings.j2"
dest: "{{app_settings}}"
- name: "{{app_name}} - manage script"
template:
src: app-manage.j2
dest: "{{manage_app_bin}}"
mode: "u=rwx,g=rx,o=rx"
- name: "{{app_name}} - migrate schemas"
command: "{{manage_app_bin}} migrate_schemas"
# FIXME
# - name: "{{app_name}} - compile translations"
# command: "{{manage_app_bin}} compile_translations"
# when: compile_translations
- name: "{{app_name}} - compile scss"
command: "{{manage_app_bin}} compile_scss"
when: compile_scss
- name: "{{app_name}} - collect statics"
shell: "echo yes | {{manage_app_bin}} collectstatic --link"
- name: "{{app_name}} - server script"
template:
src: app-server.j2
dest: "{{virtualenv}}/bin/{{server_app_name}}-server"
mode: "u=rwx,g=rx,o=rx"
- name: "{{app_name}} - server log directory"
file:
path: "{{log_dir}}"
state: directory
owner: "{{user}}"
group: "{{user}}"
become: yes
- name: "{{app_name}} - server supervisor configuration"
template:
src: server-supervisor.j2
dest: "/etc/supervisor/conf.d/{{server_app_name}}.conf"
become: yes
- name: "{{app_name}} - copy uwsgi configuration file"
copy:
src: "{{uwsgi_settings_orig}}"
dest: "{{uwsgi_settings}}"
- name: "{{app_name}} - comment cron options in uwsgi configuration file"
replace:
path: "{{uwsgi_settings}}"
regexp: '^(cron.*)'
replace: '# \1'
- name: "{{app_name}} - change http-to option in uwsgi configuration file"
ini_file:
path: "{{uwsgi_settings}}"
section: uwsgi
option: http-socket
value: ":{{server_port}}"
- name: "{{app_name}} - set py-auto-reload in uwsgi configuration file"
ini_file:
path: "{{uwsgi_settings}}"
section: uwsgi
option: py-auto-reload
value: "1"
- name: '{{app_name}} - change local configuration path in uwsgi configuration file'
replace:
path: '{{uwsgi_settings}}'
regexp: '/etc/{{project_name}}/'
replace: '{{app_settings_dir}}/settings.d/'
- name: "{{app_name}} - change py-tracebacker option in uwsgi configuration file"
ini_file:
path: "{{uwsgi_settings}}"
section: uwsgi
option: py-tracebacker
value: "{{run_dir}}/py-tracebacker.sock."
- name: "{{app_name}} - change stats option in uwsgi configuration file"
ini_file:
path: "{{uwsgi_settings}}"
section: uwsgi
option: stats
value: "{{run_dir}}/stats.sock"
- name: "{{app_name}} - uwsgi server supervisor configuration"
template:
src: server-uwsgi-supervisor.j2
dest: "/etc/supervisor/conf.d/{{server_app_name}}-uwsgi.conf"
become: yes
- name: "{{app_name}} - create some directories"
file:
path: "{{item}}"
state: directory
owner: "{{user}}"
group: "{{user}}"
become: yes
loop:
- "{{run_dir}}"
- "{{spooler_dir}}"