OMD "Labs" Edition (https://omd.consol.de/docs/omd/) on Docker with Ansible support.
Author: Sven Nierlein, sven.nierlein at consol.de
Original Author: Simon Meggle
Each image build gets triggered by the OMD Labs build system as soon as there are new packages of OMD available:
- https://hub.docker.com/r/consol/omd-labs-rocky/ (x86 / arm64)
- https://hub.docker.com/r/consol/omd-labs-debian/ (x86 / arm64)
Automated builds are triggered for the following branches:
- master => :nightly (=snapshot builds)
- vX.XX => :vX.XX (=stable version)
- latest => :latest (=latest stable version)
Each image already contains a "demo" site.
Run the "demo" site in OMD Labs Edition:
# Rocky 9
docker run -p 8443:443 consol/omd-labs-rocky
# Debian 13
docker run -p 8443:443 consol/omd-labs-debian
Use the Makefile to work with locally built images:
# run a local image
make -f Makefile.omd-labs-rocky start
# build a "local/" image without overwriting the consol/ image
make -f Makefile.omd-labs-rocky build
# start just the bash
make -f Makefile.omd-labs-rocky bash
The container will log its startup process:
Config and start OMD site: demo
--------------------------------------
Checking for volume mounts...
--------------------------------------
* local/: [No Volume]
* etc/: [No Volume]
* var/: [No Volume]
Checking for Ansible drop-in...
--------------------------------------
Nothing to do (/root/ansible_dropin/playbook.yml not found).
omd-labs: Starting site demo...
--------------------------------------
Preparing tmp directory /omd/sites/demo/tmp...Starting rrdcached...OK
Starting npcd...OK
Starting naemon...OK
Starting dedicated Apache for site demo...OK
Initializing Crontab...OK
OK
The default sitename "demo" can be changed. Build a custom image while SITENAME
is set:
- clone this repository,
cd
into the folder containg the Dockerfile, e.g.omd-labs-rocky
- build a local image:
export SITENAME=mynewsite; make -f Makefile.omd-labs-rocky build
Each container instance of this image will start the site "mynewsite" instead of "demo".
If you need to set the sitename dynamically without building the whole image from scratch (see above), you can create images with another OMD-site beneath the default site (see above). Create a custom Dockerfile
which uses the original image as the base image:
FROM: consol/omd-labs-rocky:nightly
...
...
The sitename in your custom OMD image can now be changed by setting the variable NEW_SITENAME
to a new value:
export NEW_SITENAME=anothersite
The ONBUILD commands in the original Dockerfile execute after the current Dockerfile build completes. ONBUILD executes in any child image derived FROM the current image. Think of the ONBUILD command as an instruction the parent Dockerfile gives to the child Dockerfile.
As soon as the container dies, all monitoring data (configuration files, RRD data, InfluxDB, log files etc.) are lost, too. To keep the data persistent, use host mounted volumes.
This command
make -f Makefile.omd-labs-rocky startvol
starts the container with a volume mount for the site folder:
./site/
=>$OMD_ROOT/
On the very first start, this folders will be initialized and populated.
Note: previously 3 separate mounts were used for local/
, etc/
and var/
. This is still possible, but it is recommended to use a single mount for the whole site folder.
For some time OMD-Labs comes with full Ansible support, which we can use to modify the container instance on startup. How does this work?
By default, the OMD-labs containers start with the CMD /root/start.sh
. This script
- checks if there is a
playbook.yml
in$ANSIBLE_DROPIN
(default:/root/ansible_dropin
, changeable by environment). If found, the playbook is executed. It is completely up to you if you only place one single task inplaybook.yml
, or if you also include Ansible roles. (with a certain point of complexity, you should think about a separate image, though...) - starts the OMD site "demo"
- runs system Apache in background
- waits forever
Just a folder containing a valid playbook into the container:
docker run -it -p 8443:443 -v $(pwd)/my_ansible_dropin:/root/ansible_dropin consol/omd-labs-debian
When starting the container, OMD will create a random default password for the omdadmin user. There are several ways to handle this:
- using the data volume will bring your own htpasswd file
- set your default omdadmin password per ansbible dropin, ex. like:
playbook.yml:
---
- hosts: all
tasks:
- shell: sudo su - demo -c "set_admin_password omd"
If you want to see more verbose output from Ansible to debug your role, adjust the environment variable value ANSIBLE_VERBOSITY
to e.g. 3
:
docker run -it -p 8443:443 -e ANSIBLE_VERBOSITY=3 -v $(pwd)/my_ansible_dropin:/root/ansible_dropin consol/omd-labs-debian