This guide provides a full Ansible playbook to deploy Inventaire with Docker Compose on Debian 11+, Ubuntu 20.04+, and RHEL 8+ compatible hosts. The playbook handles the complete multi-container setup including CouchDB, Elasticsearch, and the main application.
---
- name: Deploy Inventaire
hosts: inventaire
become: true
vars:
app_root: /opt/inventaire
app_port: 3000
couchdb_admin_user: "admin"
couchdb_admin_password: "replace_with_secure_password"
elasticsearch_heap_size: "1g"
inventaire_hostname: "inventaire.example.com"
smtp_host: "smtp.example.com"
smtp_port: 587
admin_email: "admin@example.com"
session_secret: "replace_with_strong_session_secret"
tasks:
- name: Install Docker on Debian/Ubuntu
apt:
name:
- docker.io
- docker-compose-plugin
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install Docker on RHEL family
package:
name:
- docker
- docker-compose-plugin
state: present
when: ansible_os_family == "RedHat"
- name: Enable and start Docker
systemd:
name: docker
state: started
enabled: true
- name: Add docker group membership for current user
user:
name: "{{ ansible_user }}"
groups: docker
append: yes
notify: restart ssh
- name: Create application directory
file:
path: "{{ app_root }}"
state: directory
mode: "0755"
- name: Create elasticsearch.yml configuration
copy:
dest: "{{ app_root }}/elasticsearch.yml"
mode: "0644"
content: |
cluster.name: "inventaire-cluster"
node.name: "es-node1"
network.host: 0.0.0.0
http.port: 9200
discovery.type: single-node
action.auto_create_index: false
notify: restart inventaire
- name: Write Docker Compose file
template:
src: docker-compose.yml.j2
dest: "{{ app_root }}/docker-compose.yml"
mode: "0644"
notify: restart inventaire
- name: Start application stack
command: docker compose up -d
args:
chdir: "{{ app_root }}"
register: docker_up_result
- name: Wait for Inventaire to be ready
uri:
url: "http://localhost:{{ app_port }}"
method: GET
status_code: 200
timeout: 10
retries: 30
delay: 10
when: docker_up_result.changed
handlers:
- name: restart inventaire
command: docker compose restart
args:
chdir: "{{ app_root }}"
listen: "restart inventaire"
- name: restart ssh
service:
name: ssh
state: restarted
listen: "restart ssh"
Create a template file at templates/docker-compose.yml.j2:
version: '3.8'
services:
couchdb:
image: couchdb:3.3
restart: unless-stopped
volumes:
- couchdb_data:/opt/couchdb/data
environment:
- COUCHDB_USER={{ couchdb_admin_user }}
- COUCHDB_PASSWORD={{ couchdb_admin_password }}
networks:
- inventaire_net
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.24
restart: unless-stopped
volumes:
- es_data:/usr/share/elasticsearch/data
- {{ app_root }}/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
environment:
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms{{ elasticsearch_heap_size }} -Xmx{{ elasticsearch_heap_size }}"
- xpack.security.enabled=false
ulimits:
memlock:
soft: -1
hard: -1
networks:
- inventaire_net
server:
image: codeberg.org/inventaire/inventaire:latest
restart: unless-stopped
depends_on:
- couchdb
- elasticsearch
ports:
- "{{ app_port }}:3000"
environment:
- INV_DATABASE_COUCHDB_URL=http://{{ couchdb_admin_user }}:{{ couchdb_admin_password }}@couchdb:5984
- INV_DATABASE_COUCHDB_NAME=inventaire
- INV_ELASTICSEARCH_HOST=elasticsearch
- INV_ELASTICSEARCH_PORT=9200
- INV_APP_HOSTNAME={{ inventaire_hostname }}
- INV_APP_PORT={{ app_port }}
- INV_EMAIL_ALERTS_TO={{ admin_email }}
- INV_SMTP_HOST={{ smtp_host }}
- INV_SMTP_PORT={{ smtp_port }}
- INV_SMTP_SECURE=false
- INV_SESSION_SECRET={{ session_secret }}
networks:
- inventaire_net
volumes:
couchdb_data:
es_data:
networks:
inventaire_net:
driver: bridge
For production deployments, consider using additional roles for:
codeberg.org/inventaire/inventaire:latest should be replaced with a specific version tag for production.Any questions?
Feel free to contact us. Find all contact information on our contact page.