Installing Odoo manually on a single server takes about an hour. But when you need to set up test, production and backup environments, and then repeat the process with every update, manual work quickly becomes a source of errors. That is why Odoo installation automation is now standard in companies that take the stability of their ERP seriously. In this article, we show how to automate the installation of Odoo 19 using a Bash script and Ansible, including configuration, a systemd service and common pitfalls.
Want to see how the system works before deploying it on your own servers? Try Odoo for free and explore the modules live.
Why automate the Odoo installation?
Automation delivers measurable benefits, especially when you manage multiple environments:
- Repeatability – every server is configured identically, with no risk of skipping a step.
- Speed – a new environment is ready in minutes instead of hours.
- Documentation as code – a playbook or script describes exactly what your infrastructure looks like.
- Easier disaster recovery – you can set up a new server with a single command.
- Version control – you keep the entire configuration in Git and can see the history of changes.
Script or Ansible – which one to choose?
Bash script
A script works well when you have one or two servers and want a running instance quickly. It is simple and requires no additional tools. Its drawback is that it is not naturally idempotent: every step that should be safe to re-run has to be guarded separately with a condition, which makes the code more complicated over time.
Ansible
Ansible is agentless and works over SSH, describes the desired state of a server and is idempotent. You can run it repeatedly, and changes are applied only where needed. It is the best choice for multiple servers and DevOps teams.
Prerequisites
Before you start, prepare the following:
- a server running Ubuntu LTS or Debian (for RHEL and derivatives, see our guide to installing Odoo 19 on CentOS/RHEL),
- SSH access with sudo privileges,
- a Python version supported by Odoo 19 (3.10 or newer; Ubuntu 22.04 ships 3.10, Ubuntu 24.04 ships 3.12, Debian 12 ships 3.11) and a PostgreSQL version compatible with the current Odoo 19 documentation,
- Ansible installed on the control machine and an inventory file with an
odoohost group (for the playbook variant).
Automated Odoo installation with a Bash script
The example below installs dependencies, creates a system user and a PostgreSQL role, downloads the Odoo 19 code from the official repository, prepares a Python virtual environment and generates a configuration file with a random master password.
#!/bin/bash
set -euo pipefail
ODOO_USER=odoo
ODOO_HOME=/opt/odoo
ODOO_CONF=/etc/odoo.conf
apt update
apt install -y git python3-venv python3-dev build-essential \
postgresql libpq-dev libxml2-dev libxslt1-dev libldap2-dev \
libsasl2-dev libjpeg-dev openssl
id $ODOO_USER >/dev/null 2>&1 || useradd -m -d $ODOO_HOME -s /bin/bash $ODOO_USER
# PostgreSQL role without superuser privileges
sudo -u postgres psql -tAc "SELECT 1 FROM pg_roles WHERE rolname='$ODOO_USER'" | grep -q 1 \
|| sudo -u postgres createuser --createdb $ODOO_USER
[ -d $ODOO_HOME/odoo-server ] || \
sudo -u $ODOO_USER git clone https://github.com/odoo/odoo --depth 1 --branch 19.0 $ODOO_HOME/odoo-server
[ -d $ODOO_HOME/venv ] || sudo -u $ODOO_USER python3 -m venv $ODOO_HOME/venv
sudo -u $ODOO_USER $ODOO_HOME/venv/bin/pip install wheel -r $ODOO_HOME/odoo-server/requirements.txt
mkdir -p /var/log/odoo
chown $ODOO_USER: /var/log/odoo
if [ ! -f $ODOO_CONF ]; then
cat > $ODOO_CONF <<EOF
[options]
admin_passwd = $(openssl rand -base64 24)
db_user = $ODOO_USER
addons_path = $ODOO_HOME/odoo-server/addons
logfile = /var/log/odoo/odoo.log
EOF
chown $ODOO_USER: $ODOO_CONF
chmod 640 $ODOO_CONF
fi
Note the checks before each step (id, pg_roles, tests for existing directories and the configuration file). They make it safe to re-run the script, and the existing configuration and master password will not be overwritten. We create the PostgreSQL role with the CREATEDB privilege rather than as a superuser, following the principle of least privilege.
A note on wkhtmltopdf: the wkhtmltopdf package from the Ubuntu and Debian repositories is built without patched Qt, so PDF reports with headers and footers may not render correctly. For Odoo, we recommend version 0.12.6.1-3 from the official wkhtmltopdf project packages. Add downloading and installing it as a separate step in the script or Ansible role.
systemd service
To make Odoo start automatically, create the unit file /etc/systemd/system/odoo.service:
[Unit]
Description=Odoo 19
After=network.target postgresql.service
[Service]
Type=simple
User=odoo
Group=odoo
ExecStart=/opt/odoo/venv/bin/python /opt/odoo/odoo-server/odoo-bin -c /etc/odoo.conf
Restart=on-failure
[Install]
WantedBy=multi-user.target
Then reload systemd and start the service:
systemctl daemon-reload
systemctl enable --now odoo
Configuring log paths is an important part of every installation, so it is worth checking our guide on how to configure file logging in Odoo.
Automating the Odoo installation with Ansible
An Ansible playbook splits the process into roles or tasks. Below is a simplified example that performs the same steps as the script, but in an idempotent way. It requires the community.postgresql collection (ansible-galaxy collection install community.postgresql):
---
- name: Odoo 19 installation
hosts: odoo
become: true
vars:
odoo_user: odoo
odoo_home: /opt/odoo
tasks:
- name: Install system packages
ansible.builtin.apt:
name: [git, acl, python3-venv, python3-dev, python3-psycopg2, build-essential, postgresql, libpq-dev, libxml2-dev, libxslt1-dev, libldap2-dev, libsasl2-dev, libjpeg-dev]
update_cache: true
- name: Create the Odoo user
ansible.builtin.user:
name: '{{ odoo_user }}'
home: '{{ odoo_home }}'
shell: /bin/bash
- name: PostgreSQL role for Odoo
community.postgresql.postgresql_user:
name: '{{ odoo_user }}'
role_attr_flags: CREATEDB
become_user: postgres
- name: Download the Odoo 19 code
ansible.builtin.git:
repo: https://github.com/odoo/odoo
dest: '{{ odoo_home }}/odoo-server'
version: '19.0'
depth: 1
become_user: '{{ odoo_user }}'
- name: Install Python dependencies
ansible.builtin.pip:
requirements: '{{ odoo_home }}/odoo-server/requirements.txt'
virtualenv: '{{ odoo_home }}/venv'
virtualenv_command: python3 -m venv
become_user: '{{ odoo_user }}'
- name: Log directory
ansible.builtin.file:
path: /var/log/odoo
state: directory
owner: '{{ odoo_user }}'
group: '{{ odoo_user }}'
mode: '0750'
- name: Odoo configuration file
ansible.builtin.template:
src: odoo.conf.j2
dest: /etc/odoo.conf
owner: '{{ odoo_user }}'
group: '{{ odoo_user }}'
mode: '0640'
notify: Restart Odoo
- name: systemd unit
ansible.builtin.template:
src: odoo.service.j2
dest: /etc/systemd/system/odoo.service
mode: '0644'
notify: Restart Odoo
- name: Enable and start the Odoo service
ansible.builtin.systemd:
name: odoo
enabled: true
state: started
daemon_reload: true
handlers:
- name: Restart Odoo
ansible.builtin.systemd:
name: odoo
state: restarted
daemon_reload: true
The odoo.conf.j2 file is a Jinja2 template in which parameters such as db_host, workers or admin_passwd come from variables, while odoo.service.j2 contains the systemd unit shown above. Always store passwords in Ansible Vault, never in plain text in the repository. As with the script, add wkhtmltopdf version 0.12.6.1-3 as a separate task, because the apt package does not include patched Qt.
Best practices for automation
- Test on a staging environment – before running the playbook in production, try it on a virtual machine or container. The
--check --diffmode is also helpful, as it shows planned changes without applying them. - Use ansible-lint – it catches common errors and deviations from standards.
- Pin versions – point to a specific Odoo branch or commit to avoid unexpected changes after the repository is updated.
- Secure the database manager – set a strong master password and restrict access. You can find details in our article about the Odoo Database Manager and how to secure it.
- Account for the firewall – open only ports 80, 443 and SSH. This guide will help: configuring a firewall for Odoo.
Fully automating a production Odoo environment, with a reverse proxy, backups and monitoring, can be difficult to set up on your own. If you want to avoid costly mistakes, get help from the experienced specialists at KK Innovations.
Extending automation with additional components
Nginx as a reverse proxy
You can add a role to the playbook that installs Nginx, Let's Encrypt certificates and traffic forwarding to port 8069 (HTTP) and 8072 (gevent, websocket handling). Port 8072 is used only when Odoo runs in multiprocessing mode (workers greater than 0). For larger deployments, you may also find this useful: configuring an Nginx load balancer for Odoo.
Redis
If you plan to scale, you can add a Redis installation to your automation. Keep in mind, however, that Odoo does not support Redis natively, so the integration requires an additional module or appropriate configuration. See how to configure Redis for Odoo.
Post-deployment diagnostics
After the playbook finishes, add a task that checks whether port 8069 is responding (e.g. the ansible.builtin.uri or wait_for module). If you run into access problems, our article on the Connection Refused error in Odoo will help.
FAQ – frequently asked questions
Is Ansible better than a Bash script for installing Odoo?
For a single server, a Bash script is perfectly sufficient. Ansible wins with multiple environments because it is idempotent, readable and easy for a team to maintain.
Can I automate the Odoo installation in Docker?
Yes. The official Odoo image and a docker-compose file are another popular method. Ansible can additionally manage the Docker host and deploy configuration files.
How do I store passwords securely in automation?
Use Ansible Vault to encrypt variables such as the administrator password or database credentials. Never add files with passwords to the repository in plain text. In a Bash script, generate the password randomly and save it only in a configuration file with restricted permissions.
Summary
Automating the Odoo installation saves time, reduces errors and makes it easier to scale your infrastructure. Start with a simple script, and as your needs grow, move to Ansible and add further roles: Nginx, backups and monitoring. If you need a ready-made, tested solution tailored to your company, the KK Innovations team will be happy to prepare it for you.
Contact KK Innovations and discuss an Odoo 19 deployment with full automation, without unnecessary risk.