- Jinja 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .forgejo/workflows | ||
| defaults | ||
| meta | ||
| tasks | ||
| templates | ||
| .gitignore | ||
| CHANGELOG.md | ||
| LICENSE | ||
| README.md | ||
Odoo
Deploys an Odoo instance via Docker Compose with PostgreSQL, optionally routed through Traefik as a reverse proxy.
Requirements
- Docker
community.dockerAnsible collectiongiton the target host (only required when using the Enterprise integration or Custom Addons)
Variables
| Variable | Default | Description |
|---|---|---|
odoo_instance |
odoo |
Unique instance name. Used as Compose project name and container name prefix. Change when running multiple instances on the same host. |
odoo_version |
19 |
Odoo image tag. Pin to a specific version in production. |
odoo_pg_image |
postgres |
PostgreSQL image. pgvector/pgvector (tag pg18) for Odoo's AI RAG; Debian-based, so switching from alpine needs a REINDEX. |
odoo_pg_version |
18-alpine |
PostgreSQL image tag. Pin to a specific version in production. |
odoo_data_path |
/data/odoo |
Host path for persistent data (PostgreSQL data, Odoo filestore, addons, config). |
odoo_docker_path |
/docker/odoo |
Host path for the compose.yml file. |
odoo_domain |
~ |
Public domain Odoo runs on (no protocol prefix). Enables Traefik routing when set. |
odoo_traefik_certresolver |
default |
Name of the Traefik certificate resolver to use for odoo_domain. Must already be defined in Traefik's static config. |
odoo_port |
~ |
Host port to expose Odoo on (maps to container port 8069). Omit when using Traefik via odoo_domain. |
odoo_pg_user |
odoo |
PostgreSQL role name. |
odoo_pg_pass |
~ |
PostgreSQL user password. Required. Generate with openssl rand -hex 32. |
odoo_uninstall |
false |
Stops and removes containers and the compose directory. |
odoo_purge |
false |
Also removes the data directory. Requires odoo_uninstall: true. Irreversible. |
odoo_enterprise_ssh_key |
~ |
SSH private key contents used to clone the Enterprise repo. Setting this enables the Enterprise integration. |
odoo_enterprise_repo |
git@github.com:odoo/enterprise.git |
SSH URL of the Odoo Enterprise repository. |
odoo_enterprise_version |
{{ odoo_version }}.0 |
Branch of odoo_enterprise_repo to check out. |
odoo_proxy_mode |
~ (on when odoo_domain is set) |
Run the server with --proxy-mode (trust the reverse proxy's X-Forwarded-* headers). Needed behind Traefik, otherwise Odoo generates http:// links. |
odoo_custom_addons |
[] |
List of custom addon repositories to clone/update. See Custom Addons. |
Usage
Minimal setup with Traefik:
odoo_domain: "odoo.example.com"
odoo_pg_pass: "{{ vault_odoo_pg_pass }}"
Using an HTTP-challenge certificate resolver for this instance only (e.g. when the default resolver uses a
DNS challenge but this Traefik also has an HTTP-challenge resolver defined, named letsencrypt-http):
odoo_domain: "odoo.example.com"
odoo_traefik_certresolver: "letsencrypt-http"
odoo_pg_pass: "{{ vault_odoo_pg_pass }}"
With a direct host port instead of Traefik:
odoo_port: 8069
odoo_pg_pass: "{{ vault_odoo_pg_pass }}"
Multiple instances on the same host:
# instance 1
odoo_instance: odoo_crm
odoo_domain: crm.example.com
odoo_pg_pass: "secret_a"
odoo_data_path: /data/odoo_crm
odoo_docker_path: /docker/odoo_crm
# instance 2
odoo_instance: odoo_erp
odoo_domain: erp.example.com
odoo_pg_pass: "secret_b"
odoo_data_path: /data/odoo_erp
odoo_docker_path: /docker/odoo_erp
First Run
On the first visit to the Odoo URL, the database manager UI is shown. Create a database there — Odoo initializes its own schema. PostgreSQL is started with POSTGRES_DB=postgres; Odoo manages the application database lifecycle directly.
Enterprise
Odoo Enterprise is an optional addon repository (https://github.com/odoo/enterprise), private and only
accessible to GitHub accounts that have been granted collaborator access by Odoo (this happens once you
have an Enterprise subscription).
To enable it:
- Add an SSH key to the GitHub account that has collaborator access to the Enterprise repo.
- Pass that key's private key contents as
odoo_enterprise_ssh_key(e.g. via Ansible Vault).
odoo_enterprise_ssh_key: "{{ vault_odoo_enterprise_ssh_key }}"
The role clones the repository into odoo_data_path/enterprise on first run and pulls the latest commit on
odoo_enterprise_version on every subsequent run, then mounts it at /mnt/extra-addons/enterprise in the
web container. The deploy key is written to odoo_docker_path/enterprise_deploy_key with mode 0600,
owned by root.
Unset odoo_enterprise_ssh_key to disable the integration again. Note that the cloned repository under
odoo_data_path/enterprise is left in place unless odoo_purge is also set.
Custom Addons
For a private, single-purpose addon module (as opposed to Enterprise's large collection of many first-party
modules), odoo_custom_addons clones/updates it directly into odoo_data_path/addons, which is already
mounted at /mnt/extra-addons — no separate addons_path entry needed, unlike Enterprise.
odoo_custom_addons:
- name: isp_onboarding
repo: "git@git.example.com:org/isp_onboarding.git"
version: "v1.2.3" # branch, tag, or commit — defaults to "master"
ssh_key: "{{ vault_isp_onboarding_deploy_key }}" # omit for a public repo
Each entry's name doubles as the Odoo technical module name: the repo's top level must be the module
(a single addon), not a collection of many, the way Enterprise is.
By itself this only keeps the code on disk in sync with version. It also goes one step further
automatically: whenever an addon's checkout actually moves to a new commit, the role queries Postgres
directly for the real application database (there's no variable for this — the name isn't something you can
be expected to know or supply; Odoo doesn't auto-create it either, see First Run). If exactly
one such database exists, it upgrades the changed addon in that database and restarts the web container (a
plain module upgrade doesn't guarantee a newly-added asset file gets picked up, since the running server
caches the parsed manifest from when it started — restarting unconditionally is simpler than trying to detect
that case).
The upgrade runs as a separate, short-lived Odoo process inside the web container
(odoo_upgrade_command: odoo -c /etc/odoo/odoo.conf --addons-path=… --db_host "$HOST" --db_user "$USER" --db_password "$PASSWORD" --i18n-overwrite --stop-after-init --no-http -d <db> -u <name>, run through
bash -c inside the container so the DB login comes from the container's own environment — never visible on
the host — rather than from odoo.conf, which is only rendered once and may lack db_* lines), not
odoo module upgrade: -u creates a new stored field's column before
anything reads it (module upgrade fails on a new field of a model read at startup, e.g. res.company),
--i18n-overwrite also updates already-translated terms from the addon's .po files, and the addons path
has to be passed because the server gets it from its command line, not from odoo.conf. If zero or more than one database exist, the upgrade step is
skipped with an explanatory message — the code still lands on disk either way, just without the automatic
upgrade.
This only ever upgrades an already-installed module — the first install of a brand new module is a
deliberate one-time action (via the Apps UI, or an explicit -i) that this role doesn't attempt on its own.
Unset an entry's ssh_key, or remove it from odoo_custom_addons entirely, to stop managing it — like
Enterprise, the checkout under odoo_data_path/addons/<name> is left in place unless odoo_purge is set.
Auto-pull
Everything above only ever happens when this role runs — i.e. a full Ansible playbook run. Set auto_pull
on an entry to additionally install a standalone systemd timer on the target host that independently checks
the repo for a new release and deploys it — no Ansible run needed:
odoo_custom_addons:
# Production: deploy release tags on master.
- name: isp_onboarding
repo: "git@git.example.com:org/isp_onboarding.git"
ssh_key: "{{ vault_isp_onboarding_deploy_key }}"
auto_pull: true
auto_pull_mode: "tag" # optional, default "tag"
auto_pull_branch: "master" # optional, default "master"
auto_pull_interval: "5min" # optional, default "5min" — a systemd OnUnitActiveSec value
# A dev instance: follow the dev branch head.
- name: isp_onboarding
repo: "git@git.example.com:org/isp_onboarding.git"
version: "dev" # same branch, so a full Ansible run agrees with auto-pull
auto_pull: true
auto_pull_mode: "branch"
auto_pull_branch: "dev"
On each tick, {{ odoo_instance }}-<name>-pull.timer runs {{ odoo_instance }}-<name>-pull.service, which
fetches auto_pull_branch and its tags and determines the release to deploy:
tagmode: the highest version-sorted tag reachable fromauto_pull_branch(git tag --merged+sort -V) — a tag pushed on any other branch is never deployed.branchmode: the head ofauto_pull_branch.
If that commit differs from what's checked out, it checks it out and runs the same
discover-the-database-then-upgrade-then-restart sequence described above — reimplemented in bash in the
rendered script, since this runs standalone, not through Ansible. Watch it with
journalctl -u {{ odoo_instance }}-<name>-pull.service.
If the upgrade fails, the checkout is put back to the previously deployed commit and the web container is
not restarted — the running server still has the old code loaded, and Odoo rolls back the failed
upgrade's database transaction. The unit then exits non-zero (a failed unit in systemd), after running
auto_pull_failure_hook if set — raw shell for a notification, with $NAME/$REPO/$failed (the release
that failed)/$previous (the commit back in place) in scope:
auto_pull_failure_hook: |
echo "$NAME: $failed failed to deploy on $(hostname)" | mail -s "Odoo deploy failed" ops@example.com
In tag mode, the Ansible task above only clones the addon if it's missing — it never updates, upgrades or
restarts for it, since the timer owns which release is deployed (otherwise a full run would check out
version again: untagged commits, or a rollback of a newer tag). version is then only what a fresh clone
starts from; the timer moves it to the latest tag on its first tick. In branch mode, the Ansible task keeps
updating as before — set version to the same branch so the two agree.
This role has no backup mechanism of its own — for that, set auto_pull_backup_hook to raw shell that's
inserted into the script verbatim, right after a new tag is found but before anything is touched (fetch,
checkout, upgrade, restart):
odoo_custom_addons:
- name: isp_onboarding
repo: "git@git.example.com:org/isp_onboarding.git"
ssh_key: "{{ vault_isp_onboarding_deploy_key }}"
auto_pull: true
auto_pull_backup_hook: |
RESTIC_REPOSITORY=sftp:mybackup:/home/myhost RESTIC_PASSWORD_FILE=/root/.restic-password-myhost restic backup /data
set -euo pipefail is already active in the script, so if the hook exits non-zero, the deploy stops right
there — nothing below it runs. $NAME/$REPO/$DEST/$latest_tag/$current_tag are all in scope if the
hook wants them (e.g. to tag a snapshot with the version being deployed; in branch mode they hold
<branch>@<short sha> and the tag or short sha currently deployed).
Uninstall
To stop and remove all containers and the compose directory:
odoo_uninstall: true
To also wipe all data including the PostgreSQL data and filestore (irreversible):
odoo_uninstall: true
odoo_purge: true
Notes
- At least one of
odoo_portorodoo_domainmust be set for Odoo to be reachable. odoo_data_path/dbis owned by70:70(PostgreSQL container user, mode0700).odoo_data_path/web,addons, andconfigare owned by100:101(Odoo container user).- Any addon dropped into
odoo_data_path/addons(manually, or automatically via Custom Addons) is picked up at the/mnt/extra-addonspath inside the container. - The role renders a default
odoo_data_path/config/odoo.confon first run (the Odoo image requires this file to exist). It is only rendered once — edit it freely afterwards (e.g. to setadmin_passwd) without it being overwritten on subsequent runs. - When
odoo_enterprise_ssh_keyis set,addons_pathis passed via acommand:override in the compose file (/mnt/extra-addons,/mnt/extra-addons/enterprise) rather than throughodoo.conf, since the config file isn't re-rendered. If you add custom paths toodoo.conf'saddons_pathyourself, list them again here too — the CLI flag takes precedence over the config file value.