mikrotik-netbox-dns-sync deployment

This commit is contained in:
bryanpedini committed 2026-11-20 20:47:02 +01:00
1 parent b5a6da16b5
commit 8d63279730
5 files changed
+77

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
.env
data
docker-compose.override.yml
+27
View File
@@ -1 +1,28 @@
# mikrotik-netbox-dns-sync Deployment # mikrotik-netbox-dns-sync Deployment
NetBox to MikroTik static DNS sync: [source/mikrotik-netbox-dns-sync](https://git.bjphoster.com/source/mikrotik-netbox-dns-sync).
Runs the script every 5 minutes on the [cron image](https://git.bjphoster.com/docker/cron) (`bryanpedini/cron`), logging to the container output. Nothing is built: the crontab and a checkout of the source repo are bind mounted, and `python3` (plus `tzdata`) is installed with `apk` when the container starts.
## Usage
```sh
cp env.example .env
chmod 600 .env
$EDITOR .env
git clone https://git.bjphoster.com/source/mikrotik-netbox-dns-sync.git data/source
docker compose up -d
```
`crontab` must be owned by `0:0`, as crond requires.
Every `SYNC_*` variable in `.env` is passed to the script without the prefix (`SYNC_NETBOX_URL` becomes `NETBOX_URL`, and so on), except `SYNC_SOURCE`, the path of the source checkout. See the source README for every variable and for the NetBox and RouterOS permissions.
`env.example` ships with `SYNC_DRY_RUN=true`. Run one sync by hand and check the plan before setting it to `false` and running `docker compose up -d` again:
```sh
docker compose exec cron python3 /jobs/netbox_dns_sync.py
docker compose logs -f
```
## Update
```sh
git -C data/source pull
```
The next run picks up the new script, no restart needed. Crontab changes need a `docker compose restart`.
+2
View File
@@ -0,0 +1,2 @@
# min hour day month weekday command
*/5 * * * * /usr/bin/python3 /jobs/netbox_dns_sync.py > /proc/1/fd/1 2>&1
+26
View File
@@ -0,0 +1,26 @@
---
services:
cron:
image: bryanpedini/cron:${CRON_VERSION}
restart: unless-stopped
entrypoint: ["sh", "-c", "apk add --no-cache python3 tzdata && exec /docker-entrypoint.sh"]
environment:
- TZ=${TZ}
- NETBOX_URL=${SYNC_NETBOX_URL}
- NETBOX_TOKEN=${SYNC_NETBOX_TOKEN}
- NETBOX_VERIFY_SSL=${SYNC_NETBOX_VERIFY_SSL}
- SUBNET=${SYNC_SUBNET}
- MIKROTIK_HOST=${SYNC_MIKROTIK_HOST}
- MIKROTIK_PORT=${SYNC_MIKROTIK_PORT}
- MIKROTIK_USER=${SYNC_MIKROTIK_USER}
- MIKROTIK_PASSWORD=${SYNC_MIKROTIK_PASSWORD}
- MIKROTIK_VERIFY_SSL=${SYNC_MIKROTIK_VERIFY_SSL}
- DNS_TTL=${SYNC_DNS_TTL}
- MANAGE_ALL_STATIC=${SYNC_MANAGE_ALL_STATIC}
- DRY_RUN=${SYNC_DRY_RUN}
- TIMEOUT=${SYNC_TIMEOUT}
- LOG_FILE=${SYNC_LOG_FILE}
- LOG_TO_CONSOLE=${SYNC_LOG_TO_CONSOLE}
volumes:
- ./crontab:/crontab/root:ro
- ${SYNC_SOURCE}:/jobs:ro
+19
View File
@@ -0,0 +1,19 @@
CRON_VERSION=1.0-alpine3.16
TZ=Europe/Rome
SYNC_SOURCE=./data/source
SYNC_NETBOX_URL=https://netbox.example.com
SYNC_NETBOX_TOKEN=nbt_changeme.changeme
SYNC_NETBOX_VERIFY_SSL=true
SYNC_SUBNET=192.0.2.0/24
SYNC_MIKROTIK_HOST=router.example.com
SYNC_MIKROTIK_PORT=8729
SYNC_MIKROTIK_USER=netbox-dns-sync
SYNC_MIKROTIK_PASSWORD=changeme
SYNC_MIKROTIK_VERIFY_SSL=false
SYNC_DNS_TTL=5m
SYNC_MANAGE_ALL_STATIC=false
SYNC_DRY_RUN=true
SYNC_TIMEOUT=15
SYNC_LOG_FILE=
SYNC_LOG_TO_CONSOLE=true