initial extraction

This commit is contained in:
mose 2022-09-28 18:35:31 +08:00
commit 0e2ff1a70c
10 changed files with 316 additions and 0 deletions

9
README.md Normal file
View File

@ -0,0 +1,9 @@
Ansible role for dokos
==========================
This role is not packaged, as it's very specific to Distrilab ansible context, but hopefully it may serve as an inspiration for other people that want to install dokos 3.x.x with ansible in their context.
This follow the manual; procedure initially tested and detailed on:
- https://md.distrilab.fr/xQu1bFRnSIWDT2qv5unzxw?both

9
defaults/main.yml Normal file
View File

@ -0,0 +1,9 @@
dokos_user: dokos-user
nvm_version: v0.39.1
node_version: v14.20.0
dodock_tag: v3.3.1
dokos_tag: v3.1.3
site_fqdn: dokos.local
admin_password: CHANGE_ME_NOW
# set a password otherwise it won't work (for now)
mysql_root_password: CHANGE_ME_NOW_TOO

View File

@ -0,0 +1,7 @@
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[mysql]
default-character-set = utf8mb4

14
handlers/main.yml Normal file
View File

@ -0,0 +1,14 @@
- name: mariadb restart
service:
name: mariadb
state: restarted
- name: nginx restart
service:
name: nginx
state: restarted
- name: frappe restart
service:
name: frappe-bench.target
state: restarted

84
tasks/dependencies.yml Normal file
View File

@ -0,0 +1,84 @@
- name: dokos | dependencies | install node 16 source
tags: packages
shell: curl -sL https://deb.nodesource.com/setup_16.x | bash -
args:
creates: /etc/apt/sources.list.d/nodesource.list
- name: dokos | dependencies | install yarn source key
tags: packages
shell: >
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg |
gpg --dearmor |
tee /usr/share/keyrings/yarnkey.gpg > /dev/null
args:
creates: /usr/share/keyrings/yarnkey.gpg
- name: dokos | dependencies | install yarn apt source
tags: packages
shell: >
echo 'deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main' |
sudo tee /etc/apt/sources.list.d/yarn.list
args:
creates: /etc/apt/sources.list.d/yarn.list
- name: dokos | dependencies | apt packages
tags: packages
package:
state: latest
update_cache: yes
name:
- git
- software-properties-common
- build-essential
- python3-dev
- python3-pip
- python3-venv
- python3-setuptools
- redis-server
- nginx
- mariadb-server-10.5
- xvfb
- libfontconfig
- wkhtmltopdf
- nodejs
- yarn
- name: dokos | dependencies | mariadb utf8 config
tags: mysql-setup
copy:
src: mariadb-90-want-utf8.cnf
dest: /etc/mysql/mariadb.conf.d/90-want-utf8.cnf
notify: mariadb restart
- name: dokos | dependencies | mariadb Set root Password
tags: mysql-setup
community.mysql.mysql_user:
check_implicit_admin: yes
host: localhost
name: root
password: "{{ mysql_root_password }}"
state: present
- name: dokos | dependencies | Add .my.cnf for root
tags: mysql-setup
template:
src: my.cnf.j2
dest: /root/.my.cnf
owner: root
group: root
mode: 0600
- name: Removes all anonymous user accounts
community.mysql.mysql_user:
name: ''
host_all: yes
state: absent
# - name: dokos | dependencies | pip install frappe-bench
# pip:
# name: frappe-bench
- name: dokos | dependencies | pip install dokos-cli
pip:
name: dokos-cli

127
tasks/install.yml Normal file
View File

@ -0,0 +1,127 @@
- name: dokos | install | install bench
become: yes
become_user: "{{ dokos_user }}"
shell: >
bash -ci "
bench init frappe-bench
--frappe-path https://gitlab.com/dokos/dodock
--frappe-branch {{ dodock_tag }}
--python /usr/local/bin/python3.10
--no-procfile"
args:
creates: "/home/{{ dokos_user }}/frappe-bench"
chdir: /home/{{ dokos_user }}
- name: dokos | install | bench setup config
become: yes
become_user: "{{ dokos_user }}"
command: bench setup config
args:
creates: "/home/{{ dokos_user }}/frappe-bench/sites/common_site_config.json"
chdir: /home/{{ dokos_user }}/frappe-bench
- name: dokos | install | get-app
become: yes
become_user: "{{ dokos_user }}"
command: bench get-app erpnext https://gitlab.com/dokos/dokos --branch {{ dokos_tag }}
args:
creates: "/home/{{ dokos_user }}/frappe-bench/apps/erpnext"
chdir: /home/{{ dokos_user }}/frappe-bench
- name: dokos | install | get-app payments
become: yes
become_user: "{{ dokos_user }}"
command: bench get-app https://gitlab.com/dokos/payments --branch v3.x.x
args:
creates: "/home/{{ dokos_user }}/frappe-bench/apps/payments"
chdir: /home/{{ dokos_user }}/frappe-bench
# - name: dokos | install | get-app hrms
# become: yes
# become_user: "{{ dokos_user }}"
# command: bench get-app https://gitlab.com/dokos/hrms --branch v3.x.x
# args:
# creates: "/home/{{ dokos_user }}/frappe-bench/apps/hrms"
# chdir: /home/{{ dokos_user }}/frappe-bench
- name: dokos | install | new-site
become: yes
become_user: "{{ dokos_user }}"
command: >
bench new-site {{ site_fqdn }}
--admin-password '{{ admin_password }}'
--mariadb-root-password '{{ mysql_root_password }}'
args:
creates: "/home/{{ dokos_user }}/frappe-bench/sites/{{ site_fqdn }}"
chdir: /home/{{ dokos_user }}/frappe-bench
# no_log: yes
# diff: no
- name: dokos | install | install-app
become: yes
become_user: "{{ dokos_user }}"
shell: bench --site {{ site_fqdn }} install-app erpnext
args:
creates: "/home/{{ dokos_user }}/frappe-bench/sites/apps.txt"
chdir: /home/{{ dokos_user }}/frappe-bench
# - name: dokos | install | install-app
# become: yes
# become_user: "{{ dokos_user }}"
# shell: bench --site {{ site_fqdn }} install-app hrms
# args:
# creates: "/home/{{ dokos_user }}/frappe-bench/sites/apps.txt"
# chdir: /home/{{ dokos_user }}/frappe-bench
- name: dokos | install | bench setup redis
become: yes
become_user: "{{ dokos_user }}"
command: bench setup redis
args:
creates: "/home/{{ dokos_user }}/frappe-bench/redis_cache.conf"
chdir: /home/{{ dokos_user }}/frappe-bench
- name: dokos | install | bench setup nginx
become: yes
become_user: "{{ dokos_user }}"
command: bench setup nginx --logging site --log_format combined
args:
creates: "/home/{{ dokos_user }}/frappe-bench/nginx.conf"
chdir: /home/{{ dokos_user }}/frappe-bench
- name: dokos | install | setup nginx
file:
src: "/home/{{ dokos_user }}/frappe-bench/config/nginx.conf"
dest: /etc/nginx/conf.d/frappe-bench.conf
state: link
notify: nginx restart
- name: dokos | install | allow http in ufw
ufw:
rule: allow
port: "80"
from_ip: "{{ trust_proxy }}"
proto: tcp
- name: dokos | install | install systemd rules
command: bench setup systemd --user dokos-user --yes
args:
creates: "/home/{{ dokos_user }}/frappe-bench/config/systemd"
chdir: /home/{{ dokos_user }}/frappe-bench
- name: dokos | install | list systemd rules
find:
paths: /home/{{ dokos_user }}/frappe-bench/config/systemd/
file_type: file
patterns:
- '*.target'
- '*.service'
register: systemd_list
- name: dokos | install | deploy systemd rules
file:
src: "{{ item.path }}"
dest: /etc/systemd/system/{{ item.path | basename }}
state: link
loop: "{{ systemd_list.files }}"
notify: frappe restart

12
tasks/main.yml Normal file
View File

@ -0,0 +1,12 @@
- block:
- import_tasks: user.yml
tags: user
- import_tasks: dependencies.yml
tags: dependencies
- import_tasks: python310.yml
tags: python310
- import_tasks: install.yml
tags: install

39
tasks/python310.yml Normal file
View File

@ -0,0 +1,39 @@
- name: dokos | python3.10 | apt packages
tags: packages
package:
state: latest
update_cache: yes
name:
- wget
- build-essential
- libncursesw5-dev
- libssl-dev
- libsqlite3-dev
- tk-dev
- libgdbm-dev
- libc6-dev
- libbz2-dev
- libffi-dev
- zlib1g-dev
- name: dokos | python3.10 | get python 3.10 source
get_url:
url: https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tgz
dest: /tmp/Python-3.10.2.tgz
- name: dokos | python3.10 | extract python 3.10 source
unarchive:
src: /tmp/Python-3.10.2.tgz
dest: /tmp/
remote_src: yes
- name: dokos | python3.10 | python 3.10 configure
command:
cmd: ./configure --enable-optimizations
chdir: /tmp/Python-3.10.2
- name: dokos | python3.10 | python 3.10 install
command:
cmd: make altinstall
chdir: /tmp/Python-3.10.2

12
tasks/user.yml Normal file
View File

@ -0,0 +1,12 @@
- name: dokos | user | create group
group:
name: "{{ dokos_user }}"
state: present
- name: dokos | user | create user
user:
name: "{{ dokos_user }}"
group: "{{ dokos_user }}"
shell: /bin/bash
state: present

3
templates/my.cnf.j2 Normal file
View File

@ -0,0 +1,3 @@
[client]
user=root
password={{ mysql_root_password }}