Update to 2022-07-25 16:00

This commit is contained in:
Daniel Berteaud 2022-07-25 16:00:15 +02:00
parent 9e88a5cd50
commit be9c0c5702
26 changed files with 387 additions and 310 deletions

View File

@ -1,7 +1,7 @@
---
# Version to deploy
n8n_version: 0.186.1
n8n_version: 0.187.2
# Root directory where n8n will be installed
n8n_root_dir: /opt/n8n
# User account under which n8n will run

View File

@ -0,0 +1,31 @@
---
# Version of Odoo to deploy
odoo_version: 15.0
# Odoo Build
odoo_build: 20220725
# URL of the archive
odoo_archive_url: https://nightly.odoo.com/{{ odoo_version }}/nightly/tgz/odoo_{{ odoo_version }}.{{ odoo_build }}.tar.gz
# Checksum of the archive
odoo_archive_sha256: eabc25772065e246158969e6b71d2bb160e65a5b4ae2084cfa47ecd959a6f454
odoo_root_dir: /opt/odoo
# User under which odoo will run (will be created if needed
odoo_user: odoo
# Database settings
odoo_db_server: "{{ pg_server | default('localhost') }}"
odoo_db_name: odoo
odoo_db_user: odoo
# If not defined, a random password will be generated and stored under {{ odoo_root_dir }}/meta
# odoo_db_pass: secret
# List of IP/CIDR which will be able to reach Odoo ports
odoo_src_ip: []
odoo_http_port: 8069
odoo_longpolling_port: 8072
odoo_ports: [ "{{ odoo_http_port }}","{{ odoo_longpolling_port }}" ]
odoo_workers: 4
odoo_email: "{{ system_admin_email | default('admin' + ansible_domain ) }}"

7
roles/odoo/meta/main.yml Normal file
View File

@ -0,0 +1,7 @@
---
dependencies:
- role: mkdir
- role: wkhtmltopdf
- role: postgresql_server
when: odoo_db_server in ['localhost', '127.0.0.1']

View File

@ -0,0 +1,14 @@
---
- name: Compress previous version
command: tar cf {{ odoo_root_dir }}/archives/{{ odoo_current_version }}.tar.zst --use-compress-program=zstd ./
args:
chdir: "{{ odoo_root_dir }}/archives/{{ odoo_current_version }}"
warn: False
environment:
ZSTD_CLEVEL: 10
tags: odoo
- name: Remove archive tmp dir
file: path={{ odoo_root_dir }}/archives/{{ odoo_current_version }} state=absent
tags: odoo

View File

@ -0,0 +1,42 @@
---
- name: Create the archive dir
file: path={{ odoo_root_dir }}/archives/{{ odoo_current_version }} state=directory
tags: odoo
- name: Install postgresql client
package:
name:
- postgresql14
tags: odoo
- name: Stop the server during upgrade
service: name=odoo-server state=stopped
tags: odoo
- name: Archive previous version
synchronize:
src: "{{ odoo_root_dir }}/{{ item }}"
dest: "{{ odoo_root_dir }}/archives/{{ odoo_current_version }}/"
recursive: True
delete: True
compress: False
loop:
- venv
- app
delegate_to: "{{ inventory_hostname }}"
tags: odoo
- name: Dump the database
command: >
/usr/pgsql-14/bin/pg_dump
--clean
--create
--host={{ odoo_db_server | quote }}
--port={{ odoo_db_port | quote }}
--username={{ odoo_db_user }} {{ odoo_db_name | quote }}
--file="{{ odoo_root_dir }}/archives/{{ odoo_current_version }}/{{ odoo_db_name }}.sql"
environment:
- PGPASSWORD: "{{ odoo_db_pass }}"
tags: odoo

View File

@ -0,0 +1,8 @@
---
- name: Remove temp files
file: path={{ item }} state=absent
with_items:
- "{{ odoo_root_dir }}/tmp/odoo_{{ odoo_version }}.{{ odoo_build }}.tar.gz"
- "{{ odoo_root_dir }}/tmp/odoo-{{ odoo_version }}.post{{ odoo_build }}"
tags: odoo

20
roles/odoo/tasks/conf.yml Normal file
View File

@ -0,0 +1,20 @@
---
- name: Deploy server configuration
template: src=odoo-server.conf.j2 dest={{ odoo_root_dir }}/etc/odoo-server.conf group={{ odoo_user }} mode=640
notify: restart odoo-server
tags: odoo
- when: odoo_install_mode != 'none'
block:
- name: Install odoo
command: "{{ odoo_root_dir }}/venv/bin/python3 {{ odoo_root_dir }}/app/setup.py install"
args:
chdir: "{{ odoo_root_dir }}/app/"
- name: Initialize the DB and update modules
command: "{{ odoo_root_dir }}/venv/bin/python3 {{ odoo_root_dir }}/app/setup/odoo -d {{ odoo_db_name }} -i base -u all --stop-after-init --syslog"
become_user: "{{ odoo_user }}"
tags: odoo

View File

@ -0,0 +1,22 @@
---
- name: Create directories
file: path={{ item.path }} state=directory owner={{ item.owner | default(omit) }} group={{ item.group | default(omit) }} mode={{ item.mode | default(omit) }}
with_items:
- path: "{{ odoo_root_dir }}"
owner: "{{ odoo_user }}"
mode: 700
- path: "{{ odoo_root_dir }}/tmp"
- path: "{{ odoo_root_dir }}/meta"
mode: 700
- path: "{{ odoo_root_dir }}/etc"
group: "{{ odoo_user }}"
mode: 750
- path: "{{ odoo_root_dir }}/app"
- path: "{{ odoo_root_dir }}/backup"
mode: 700
- path: "{{ odoo_root_dir }}/data"
group: "{{ odoo_user }}"
mode: 770
tags: odoo

View File

@ -0,0 +1,29 @@
---
# Load distribution specific variables
- include_vars: "{{ item }}"
with_first_found:
- "{{ role_path }}/vars/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
- "{{ role_path }}/vars/{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
- "{{ role_path }}/vars/{{ ansible_distribution }}.yml"
- "{{ role_path }}/vars/{{ ansible_os_family }}.yml"
tags: odoo
- name: Detect installed version
block:
- import_tasks: ../includes/webapps_set_install_mode.yml
vars:
- root_dir: "{{ odoo_root_dir }}"
- version: "{{ odoo_version }}-{{ odoo_build }}"
- set_fact: odoo_install_mode={{ install_mode | default('none') }}
- set_fact: odoo_current_version={{ current_version | default('') }}
tags: odoo
# Create a random pass for the DB if needed
- block:
- import_tasks: ../includes/get_rand_pass.yml
vars:
- pass_file: "{{ odoo_root_dir }}/meta/ansible_dbpass"
- set_fact: odoo_db_pass={{ rand_pass }}
when: odoo_db_pass is not defined
tags: odoo

View File

@ -0,0 +1,100 @@
---
- name: Install packages
package: name={{ odoo_packages }}
tags: odoo
- when: odoo_install_mode != 'none'
block:
- name: Fetch odoo sources
get_url:
url: "{{ odoo_archive_url }}"
dest: "{{ odoo_root_dir }}/tmp"
checksum: sha256:{{ odoo_archive_sha256 }}
- name: Extract odoo archive
unarchive:
src: "{{ odoo_root_dir }}/tmp/odoo_{{ odoo_version }}.{{ odoo_build }}.tar.gz"
dest: "{{ odoo_root_dir }}/tmp"
remote_src: True
- name: Copy odoo application to its final directory
synchronize:
src: "{{ odoo_root_dir }}/tmp/odoo-{{ odoo_version }}.post{{ odoo_build }}/"
dest: "{{ odoo_root_dir }}/app/"
recursive: True
delete: True
compress: False
delegate_to: "{{ inventory_hostname }}"
tags: odoo
- name: Create the venv
pip:
name: "{{ item }}"
state: "{{ (odoo_install_mode == 'none') | ternary('present', 'latest') }}"
virtualenv: "{{ odoo_root_dir }}/venv"
virtualenv_command: "{{ odoo_venv_command }}"
loop:
- phonenumbers
tags: odoo
- name: Create the virtualenv
pip:
state: "{{ (odoo_install_mode == 'none') | ternary('present', 'latest') }}"
virtualenv: "{{ odoo_root_dir }}/venv"
virtualenv_command: "{{ odoo_venv_command }}"
requirements: "{{ odoo_root_dir }}/app/requirements.txt"
environment:
PATH: "{{ (pg_version == 'default') | ternary('', '/usr/pgsql-' ~ pg_version ~ '/bin:') }}/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
tags: odoo
- name: Install additional modules in the venv
pip:
name: "{{ item }}"
state: "{{ (odoo_install_mode == 'none') | ternary('present', 'latest') }}"
virtualenv: "{{ odoo_root_dir }}/venv"
virtualenv_command: "{{ odoo_venv_command }}"
loop:
- phonenumbers
tags: odoo
- name: Create the PostgreSQL role
postgresql_user:
db: postgres
name: "{{ odoo_db_user }}"
password: "{{ odoo_db_pass }}"
login_host: "{{ odoo_db_server }}"
login_user: sqladmin
login_password: "{{ pg_admin_pass }}"
tags: odoo
- name: Create the PostgreSQL database
postgresql_db:
name: "{{ odoo_db_name }}"
encoding: UTF-8
template: template0
owner: "{{ odoo_db_user }}"
login_host: "{{ odoo_db_server }}"
login_user: sqladmin
login_password: "{{ pg_admin_pass }}"
tags: odoo
- name: Deploy odoo service file
template: src=odoo-server.service.j2 dest=/etc/systemd/system/odoo-server.service
register: odoo_unit
notify: restart odoo-server
tags: odoo
- name: Reload systemd
command: systemctl daemon-reload
when: odoo_unit.changed
tags: odoo
- name: Install backup hooks
template: src={{ item }}-backup.sh.j2 dest=/etc/backup/{{ item }}.d/odoo.sh mode=750
loop:
- pre
- post
tags: odoo

View File

@ -0,0 +1,8 @@
---
- name: Handle odoo ports
iptables_raw:
name: odoo_ports
state: "{{ (odoo_src_ip | length > 0) | ternary('present','absent') }}"
rules: "-A INPUT -m state --state NEW -p tcp -m multiport --dports {{ odoo_ports | join(',') }} -s {{ odoo_src_ip | join(',') }} -j ACCEPT"
tags: firewall,odoo

37
roles/odoo/tasks/main.yml Normal file
View File

@ -0,0 +1,37 @@
---
- include_tasks: user.yml
tags: always
- include_tasks: directories.yml
tags: always
- include_tasks: facts.yml
tags: always
- include_tasks: archive_pre.yml
when: odoo_install_mode == 'upgrade'
tags: always
- include_tasks: install.yml
tags: always
- include_tasks: conf.yml
tags: always
- include_tasks: iptables.yml
when: iptables_manage | default(True)
tags: always
- include_tasks: services.yml
tags: always
- include_tasks: write_version.yml
tags: always
- include_tasks: archive_post.yml
when: odoo_install_mode == 'upgrade'
tags: always
- include_tasks: cleanup.yml
tags: always

View File

@ -0,0 +1,5 @@
---
- name: Start the service
service: name=odoo-server state=started enabled=True
tags: odoo

View File

@ -0,0 +1,9 @@
---
- name: Create user account for odoo
user:
name: "{{ odoo_user }}"
system: True
shell: /sbin/nologin
home: "{{ odoo_root_dir }}"
tags: odoo

View File

@ -0,0 +1,5 @@
---
- name: Write version
copy: content={{ odoo_version }}-{{ odoo_build }} dest={{ odoo_root_dir }}/meta/ansible_version
tags: odoo

View File

@ -5,7 +5,10 @@ db_user = {{ odoo_db_user }}
db_password = {{ odoo_db_pass }}
addons_path = {{ odoo_root_dir }}/app/odoo/addons
workers = {{ odoo_workers }}
http_port = {{ odoo_xmlrpc_port }}
http_port = {{ odoo_http_port }}
longpolling_port = {{ odoo_longpolling_port }}
email_from = {{ odoo_email }}
smtp_server = localhost
data_dir = {{ odoo_root_dir }}/data
without_demo = ALL
init = base

View File

@ -0,0 +1,22 @@
[Unit]
Description=Odoo Server
After=network.service
[Service]
Type=simple
User={{ odoo_user }}
Group={{ odoo_user }}
ExecStart={{ odoo_root_dir }}/venv/bin/python3 {{ odoo_root_dir }}/app/setup/odoo -c {{ odoo_root_dir }}/etc/odoo-server.conf --proxy-mode --no-database-list
PrivateTmp=yes
PrivateDevices=yes
ProtectSystem=full
ProtectHome=yes
NoNewPrivileges=yes
SyslogIdentifier=odoo
Restart=on-failure
StartLimitInterval=0
RestartSec=30
MemoryLimit=2048M
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,5 @@
#!/bin/sh
set -eo pipefail
rm -f {{ odoo_root_dir }}/backup/*

View File

@ -2,10 +2,10 @@
set -eo pipefail
PGPASSWORD={{ odoo_db_pass | quote }} /usr/bin/pg_dump \
PGPASSWORD={{ odoo_db_pass | quote }} /usr/pgsql-14/bin/pg_dump \
--format=custom \
--clean \
--username={{ odoo_db_user }} \
--host={{ odoo_db_server }} \
--file={{ odoo_root_dir }}/db_dumps/{{ odoo_db_name }}.sqlc \
--file={{ odoo_root_dir }}/backup/{{ odoo_db_name }}.sqlc \
{{ odoo_db_name }}

View File

@ -0,0 +1,16 @@
---
odoo_packages:
- python39-pip
- python39-devel
- gcc
- gcc-c++
- libxml2-devel
- libxslt-devel
- openldap-devel
- postgresql-devel
#- nodejs-less
- tar
- zstd
odoo_venv_command: /bin/python3.9 -m venv

View File

@ -1,18 +0,0 @@
---
odoo_root_dir: /opt/odoo
odoo_version: 11.0
odoo_build: 20180301
odoo_manage_upgrade: True
odoo_archive_url: https://nightly.odoo.com/11.0/nightly/src/odoo_{{ odoo_version }}.{{ odoo_build }}.tar.gz
odoo_user: odoo
odoo_db_server: "{{ pg_server | default('localhost') }}"
odoo_db_name: odoo
odoo_db_user: odoo
# odoo_db_pass: secret
odoo_workers: 4
odoo_src_ip: []
odoo_xmlrpc_port: 8069
odoo_longpolling_port: 8072
odoo_ports: [ "{{ odoo_xmlrpc_port }}","{{ odoo_longpolling_port }}" ]
odoo_email: "{{ system_admin_email | default('admin' + ansible_domain ) }}"

View File

@ -1,4 +0,0 @@
---
dependencies:
- role: repo_scl

View File

@ -1,264 +0,0 @@
---
- name: Set default install mode to none
set_fact: odoo_install_mode="none"
tags: odoo
- name: Check if odoo is installed
stat: path={{ odoo_root_dir }}/meta/ansible_version
register: odoo_version_file
tags: odoo
- name: Check installed version
command: cat {{ odoo_root_dir }}/meta/ansible_version
register: odoo_current_version
changed_when: False
when: odoo_version_file.stat.exists
tags: odoo
- name: Set install mode to install
set_fact: odoo_install_mode='install'
when: not odoo_version_file.stat.exists
tags: odoo
- name: Set install mode to upgrade
set_fact: odoo_install_mode='upgrade'
when:
- odoo_version_file.stat.exists
- odoo_current_version is defined
- odoo_current_version.stdout != odoo_version | string + '-' + odoo_build | string
- odoo_manage_upgrade
tags: odoo
- name: Install dependencies
yum:
name:
- rh-python36-python-virtualenv
- rh-python36-python-pip
- gcc
- libxml2-devel
- libxslt-devel
- openldap-devel
- nodejs-less
- wkhtmltopdf
- python-psycopg2
- postgresql
tags: odoo
- name: Create user account for odoo
user:
name: odoo
system: True
shell: /sbin/nologin
home: "{{ odoo_root_dir }}"
tags: odoo
- name: Create directories
file: path={{ item.path }} state=directory owner={{ item.owner | default(omit) }} group={{ item.group | default(omit) }} mode={{ item.mode | default(omit) }}
with_items:
- path: "{{ odoo_root_dir }}"
owner: "{{ odoo_user }}"
mode: 700
- path: "{{ odoo_root_dir }}/tmp"
- path: "{{ odoo_root_dir }}/meta"
mode: 700
- path: "{{ odoo_root_dir }}/etc"
group: "{{ odoo_user }}"
mode: 750
- path: "{{ odoo_root_dir }}/app"
- path: "{{ odoo_root_dir }}/db_dumps"
mode: 700
- path: "{{ odoo_root_dir }}/data"
group: "{{ odoo_user }}"
mode: 770
tags: odoo
- name: Fetch odoo sources
get_url:
url: "{{ odoo_archive_url }}"
dest: "{{ odoo_root_dir }}/tmp"
when: odoo_install_mode != "none"
tags: odoo
- name: Extract odoo archive
unarchive:
src: "{{ odoo_root_dir }}/tmp/odoo_{{ odoo_version }}.{{ odoo_build }}.tar.gz"
dest: "{{ odoo_root_dir }}/tmp"
remote_src: yes
when: odoo_install_mode != "none"
tags: odoo
- name: Create archive dir
file: path={{ odoo_root_dir }}/archives/{{ odoo_current_version.stdout }} state=directory mode=700
when: odoo_install_mode == "upgrade"
tags: odoo
- name: Stop the server during upgrade
service: name=odoo-server state=stopped
when: odoo_install_mode == "upgrade"
tags: odoo
- name: Archive current Odoo install
synchronize:
src: "{{ odoo_root_dir }}/app"
dest: "{{ odoo_root_dir }}/archives/{{ odoo_current_version.stdout }}/app"
recursive: True
delegate_to: "{{ inventory_hostname }}"
when: odoo_install_mode == "upgrade"
tags: odoo
- name: Dump database
postgresql_db:
name: "{{ odoo_db_name }}"
state: dump
login_host: "{{ odoo_db_server }}"
login_user: sqladmin
login_password: "{{ pg_admin_pass }}"
target: "{{ odoo_root_dir }}/archives/{{ odoo_current_version.stdout }}/{{ odoo_db_name }}.sql.gz"
when: odoo_install_mode == "upgrade"
tags: odoo
- name: Compress previous version
command: tar cf {{ odoo_root_dir }}/archives/{{ odoo_current_version.stdout }}.txz ./
environment:
XZ_OPT: -T0
args:
chdir: "{{ odoo_root_dir }}/archives/{{ odoo_current_version.stdout }}"
when: odoo_install_mode == 'upgrade'
tags: odoo
- name: Remove the archive directory
file: path={{ odoo_root_dir }}/archives/{{ odoo_current_version.stdout }} state=absent
tags: odoo
- name: Create the virtualenv
pip:
state: latest
virtualenv: "{{ odoo_root_dir }}"
virtualenv_command: /opt/rh/rh-python36/root/usr/bin/virtualenv
requirements: "{{ odoo_root_dir }}/tmp/odoo-{{ odoo_version }}.post{{ odoo_build }}/requirements.txt"
when: odoo_install_mode != "none"
tags: odoo
- name: Install additional python modules
pip:
name: "{{ item }}"
state: latest
virtualenv: "{{ odoo_root_dir }}"
virtualenv_command: /opt/rh/rh-python36/root/usr/bin/virtualenv
with_items:
- phonenumbers
tags: odoo
- name: Copy odoo application to its final directory
synchronize:
src: "{{ odoo_root_dir }}/tmp/odoo-{{ odoo_version }}.post{{ odoo_build }}/"
dest: "{{ odoo_root_dir }}/app/"
recursive: True
delete: True
when: odoo_install_mode != "none"
delegate_to: "{{ inventory_hostname }}"
tags: odoo
- name: Install odoo
command: "{{ odoo_root_dir }}/bin/python3 {{ odoo_root_dir }}/app/setup.py install"
args:
chdir: "{{ odoo_root_dir }}/app/"
when: odoo_install_mode != "none"
tags: odoo
- name: Generate a random pass for the database
shell: openssl rand -base64 45 > {{ odoo_root_dir }}/meta/ansible_dbpass
args:
creates: "{{ odoo_root_dir }}/meta/ansible_dbpass"
when: odoo_db_pass is not defined
tags: odoo
- name: Read database password
command: cat {{ odoo_root_dir }}/meta/ansible_dbpass
register: odoo_rand_pass
when: odoo_db_pass is not defined
changed_when: False
tags: odoo
- name: Set database pass
set_fact: odoo_db_pass={{ odoo_rand_pass.stdout }}
when: odoo_db_pass is not defined
tags: odoo
- name: Create the PostgreSQL role
postgresql_user:
db: postgres
name: "{{ odoo_db_user }}"
password: "{{ odoo_db_pass }}"
login_host: "{{ odoo_db_server }}"
login_user: sqladmin
login_password: "{{ pg_admin_pass }}"
tags: odoo
- name: Create the PostgreSQL database
postgresql_db:
name: "{{ odoo_db_name }}"
encoding: UTF-8
lc_collate: C
lc_ctype: C
template: template0
owner: "{{ odoo_db_user }}"
login_host: "{{ odoo_db_server }}"
login_user: sqladmin
login_password: "{{ pg_admin_pass }}"
tags: odoo
- name: Handle odoo ports
iptables_raw:
name: odoo_ports
state: "{{ (odoo_src_ip | length > 0) | ternary('present','absent') }}"
rules: "-A INPUT -m state --state NEW -p tcp -m multiport --dports {{ odoo_ports | join(',') }} -s {{ odoo_src_ip | join(',') }} -j ACCEPT"
tags: [firewall,odoo]
- name: Deploy server configuration
template: src=odoo-server.conf.j2 dest={{ odoo_root_dir }}/etc/odoo-server.conf group={{ odoo_user }} mode=640
notify: restart odoo-server
tags: odoo
- name: Deploy odoo service file
template: src=odoo-server.service.j2 dest=/etc/systemd/system/odoo-server.service
register: odoo_unit
notify: restart odoo-server
tags: odoo
- name: Reload systemd
command: systemctl daemon-reload
when: odoo_unit.changed
tags: odoo
- name: Update modules
command: "{{ odoo_root_dir }}/bin/python3 {{ odoo_root_dir }}/app/setup/odoo -u all --stop-after-init --syslog"
become_user: "{{ odoo_user }}"
when: odoo_install_mode == "upgrade"
tags: odoo
- name: Write version
copy: content={{ odoo_version }}-{{ odoo_build }} dest={{ odoo_root_dir }}/meta/ansible_version
when: odoo_install_mode != "none"
tags: odoo
- name: Start the service
service: name=odoo-server state=started enabled=True
tags: odoo
- name: Install pre and post backup scripts
template: src={{ item.src }} dest=/etc/backup/{{ item.dest }}/odoo.sh mode=750
with_items:
- src: pre-backup.sh.j2
dest: pre.d
- src: post-backup.sh.j2
dest: post.d
tags: odoo
- name: Remove temp files
file: path={{ item }} state=absent
with_items:
- "{{ odoo_root_dir }}/tmp/odoo_{{ odoo_version }}.{{ odoo_build }}.tar.gz"
- "{{ odoo_root_dir }}/tmp/odoo-{{ odoo_version }}.post{{ odoo_build }}"
tags: odoo

View File

@ -1,17 +0,0 @@
[Unit]
Description=Odoo Server
After=network.service
[Service]
Type=simple
User={{ odoo_user }}
Group={{ odoo_user }}
ExecStart={{ odoo_root_dir }}/bin/python3 {{ odoo_root_dir }}/app/setup/odoo -c {{ odoo_root_dir }}/etc/odoo-server.conf --proxy-mode --no-database-list --without-demo=ALL --data-dir={{ odoo_root_dir }}/data
PrivateTmp=yes
PrivateDevices=yes
ProtectSystem=full
ProtectHome=yes
NoNewPrivileges=yes
[Install]
WantedBy=multi-user.target

View File

@ -1,3 +0,0 @@
#!/bin/sh
rm -f {{ odoo_root_dir }}/db_dumps/*