Dyndns Ansible Role
- Jinja 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .gitea/workflows | ||
| defaults | ||
| meta | ||
| tasks | ||
| templates | ||
| .gitignore | ||
| CHANGELOG.md | ||
| LICENSE | ||
| README.md | ||
dyndns
Installs a shell script and cron job that tracks the host's public IP and updates Hetzner DNS A records whenever it changes.
Requirements
cronandcurl(installed automatically)- Hetzner DNS API token(s)
Variables
| Variable | Default | Description |
|---|---|---|
dyndns_path |
/dyndns |
Base directory for per-zone configuration. See Usage for the expected layout. |
dyndns_interval |
*/5 |
Cron minute expression controlling how often the IP check runs. |
dyndns_uninstall |
false |
Removes the cron job and the dyndns script. |
dyndns_purge |
false |
Also removes dyndns_path. Requires dyndns_uninstall: true. Irreversible. |
Usage
Directory layout
The script reads zone configuration from subdirectories of dyndns_path. Each subdirectory name is a DNS zone ID, and must contain:
.token— Hetzner DNS API token for that zone- One file per record name to update (filename = record name, content ignored)
/dyndns/
└── <zone-id>/
├── .token
├── home # updates home.<zone>
└── vpn # updates vpn.<zone>
Populate these files before or after running the role. The script skips any zone directory that is missing a .token file.
Custom interval
dyndns_interval: "*/10" # check every 10 minutes
Custom base path
dyndns_path: /etc/dyndns
Managing individual records
Use tasks/record.yml as a standalone include to add or remove a single record without re-running the full role:
- ansible.builtin.include_role:
name: dyndns
tasks_from: record
vars:
dyndns_zone: "<zone-id>"
dyndns_record: "home"
dyndns_record_state: present # or absent
The task requires the zone directory to already exist (i.e. the role has been run for that zone). dyndns_record_state defaults to present if omitted.
Uninstall
To remove the cron job and the script:
dyndns_uninstall: true
To also remove the configuration directory (irreversible):
dyndns_uninstall: true
dyndns_purge: true
Notes
- The script installs to
/usr/local/bin/dyndnsand runs as root. - Public IP is resolved via
ipinfo.io,ipecho.net, andcheckip.amazonaws.comin order; the first successful response wins. - Updates are skipped when the IP has not changed since the last run (tracked in
dyndns_path/.last_ip). - All output is appended to
/var/log/dyndns.log.