ansible/roles/hackmd/tasks/main.yml

85 lines
2.7 KiB
YAML
Raw Normal View History

2018-04-09 21:28:36 +02:00
---
- name: Create user
user: name=hackmd
- name: Enable https for apt
apt: name=apt-transport-https
- name: Enable nodesource apt-key
apt_key: url='https://deb.nodesource.com/gpgkey/nodesource.gpg.key'
- name: Enable nodesource repository
apt_repository: repo='deb https://deb.nodesource.com/node_8.x stretch main'
- name: Install packages
apt: name={{ item }}
with_items:
- build-essential
- git
- nodejs
- postgresql
- python-psycopg2
- name: Unpack hackmd
2018-10-08 20:28:06 +02:00
unarchive: src=https://github.com/hackmdio/codimd/archive/{{ hackmd_version }}.tar.gz dest=/opt owner=hackmd remote_src=yes creates=/opt/codimd-{{ hackmd_version }}
2018-04-09 21:28:36 +02:00
register: hackmd_unarchive
- name: Setup hackmd
2018-10-08 20:28:06 +02:00
command: bin/setup chdir=/opt/codimd-{{ hackmd_version }} creates=/opt/codimd-{{ hackmd_version }}/config.json
2018-04-09 21:28:36 +02:00
become: true
become_user: hackmd
- name: Configure hackmd
2018-10-08 20:28:06 +02:00
template: src=config.json.j2 dest=/opt/codimd-{{ hackmd_version }}/config.json owner=hackmd
2018-04-09 21:28:36 +02:00
register: hackmd_config
notify: Restart hackmd
2018-04-09 21:28:36 +02:00
- name: Build hackmd frontend
2018-10-08 20:28:06 +02:00
command: /usr/bin/npm run build chdir=/opt/codimd-{{ hackmd_version }}
2018-04-09 21:28:36 +02:00
become: true
become_user: hackmd
when: (hackmd_unarchive is defined and hackmd_unarchive.changed) or (hackmd_config is defined and hackmd_config.changed)
2018-04-09 21:28:36 +02:00
- name: Configure PostgreSQL database
postgresql_db: name={{ hackmd_dbname }}
become: true
become_user: postgres
- name: Configure PostgreSQL user
postgresql_user: db={{ hackmd_dbname }} name={{ hackmd_dbuser }} password={{ hackmd_dbpass }} priv=ALL state=present
become: true
become_user: postgres
2018-10-08 20:29:18 +02:00
- name: Configure sequelize
template: src=_sequelizerc.j2 dest=/opt/codimd-{{ hackmd_version }}/.sequelizerc owner=hackmd
- name: Upgrade database schema
command: node_modules/.bin/sequelize db:migrate chdir=/opt/codimd-{{ hackmd_version }}
become: true
become_user: hackmd
2018-04-09 21:28:36 +02:00
- name: Ensure certificates are available
command: openssl req -x509 -nodes -newkey rsa:2048 -keyout /etc/nginx/ssl/{{ hackmd_domain }}.key -out /etc/nginx/ssl/{{ hackmd_domain }}.crt -days 730 -subj "/CN={{ hackmd_domain }}" creates=/etc/nginx/ssl/{{ hackmd_domain }}.crt
notify: Restart nginx
- name: Configure certificate manager for hackmd
template: src=certs.j2 dest=/etc/acme/domains.d/{{ hackmd_domain }}.conf
- name: Configure vhost
template: src=vhost.j2 dest=/etc/nginx/sites-available/hackmd
notify: Restart nginx
- name: Enable vhost
file: src=/etc/nginx/sites-available/hackmd dest=/etc/nginx/sites-enabled/hackmd state=link
notify: Restart nginx
- name: Systemd unit for hackmd
template: src=hackmd.service.j2 dest=/etc/systemd/system/hackmd.service
notify:
- Reload systemd
- Restart hackmd
- name: Start the hackmd service
service: name=hackmd state=started enabled=yes