Updated the 'Configure Time Synchronization' task to use the new 'ntp' service instead of 'ntpd'. This change simplifies the configuration and improves consistency with other services.
Ansible Role: samba_ad_dc
Ansible role to install, provision, and optionally remove a Samba Active Directory Domain Controller (AD DC) on Debian‑based systems (Debian, Ubuntu, etc.).
✅ Features
- Installs & configures Samba as an AD DC
- Provisions the domain with
samba-tool - Idempotent – skips provisioning if the domain is already present
- Reversible –
state: absentcleans up the DC - Sets up
/etc/hosts+ a static/etc/resolv.conf - Disables services that would otherwise overwrite
/etc/resolv.conf
(systemd‑resolved,resolvconf,NetworkManagerDNS,dhclient) - Configures a local NTP daemon (
ntp.conf+ntp_signd) for time‑sync - Keeps a per‑host backup of the Samba config files
- Molecule tests cover both
presentandabsentstates
📦 Role Variables
Core Samba / Kerberos variables
| Variable | Description | Default value |
|---|---|---|
samba_ad_dc_state |
present → install, absent → remove |
present |
samba_realm |
Kerberos realm (e.g., CORP.EXAMPLE.COM) |
EXAMPLE.COM |
samba_domain |
NetBIOS domain name (e.g., CORP) |
EXAMPLE |
samba_admin_password |
Password for the domain administrator | StrongAdminPassword123! |
samba_dns_backend |
DNS backend (SAMBA_INTERNAL/BIND9_DLZ) |
SAMBA_INTERNAL |
samba_hostname |
Hostname that will appear in smb.conf |
inventory_hostname |
Extended configuration variables (see defaults/main.yml)
| Variable | Description | Default value |
|---|---|---|
samba_packages |
Packages to install when state: present. Includes the full list needed for a Debian/Ubuntu AD DC. |
See the YAML block below |
location_internal_dns |
Internal DNS server used in /etc/resolv.conf |
192.168.1.1 |
location_external_dns |
External (fallback) DNS server | 8.8.8.8 |
backup_path |
Directory where the role will store a backup of | |
/etc/samba, /etc/krb5.conf, and other files. |
"/path/to/your/backup/directory" |
Note
– the
samba_packagesblock is kept for clarity, but it is not an Ansible variable you set on the host; it simply holds the list thattasks/install.ymluses.
NTP configuration
The role also deploys an NTP daemon (file: tasks/ntpd.yml):
/etc/ntp.confis rendered fromtemplates/ntp.conf.j2- The NTP service is enabled & started automatically
- The handler
Restart ntp serviceis called whenever the config changes
DNS‑prep
tasks/preparing.yml performs the following important housekeeping steps
before any Samba configuration:
- Stops and disables
systemd-resolved(if present). - Removes
/etc/resolv.confwhen it is a symlink to the resolver. - Creates a static
/etc/resolv.confthat contains both your internal and external nameservers (location_internal_dns,location_external_dns). - Uninstalls the
resolvconfpackage (if it is installed). - Prevents NetworkManager from writing DNS entries by editing
/etc/NetworkManager/NetworkManager.conf. - Prevents
dhclientfrom touching/etc/resolv.conf(implementation left to the user – you can add ablockinfiletask or a similar file‑lock).
Tip
– if you ever run into “no DNS resolution” on the host after the role has finished, double‑check that
systemd-resolvedis truly disabled and that/etc/resolv.confis not a symlink.
📁 Included Task Files
| File | Purpose |
|---|---|
tasks/install.yml |
Installs packages, configures NTP & DNS, then provisions Samba |
tasks/remove.yml |
Stops & removes Samba packages + cleans up files |
tasks/kerberos.yml |
Copies krb5.conf.j2 → /etc/krb5.conf |
tasks/verify.yml |
Runs samba-tool checks + kinit tests |
tasks/dns_hosts.yml |
Ensures /etc/hosts contains the DC record |
tasks/logging.yml |
Stores provisioning output to a log file |
tasks/preparing.yml |
Disables systemd-resolved, resolvconf, NetworkManager, and creates a static /etc/resolv.conf |
tasks/ntpd.yml |
Configures NTP (template ntp.conf.j2) and ensures it is running |
🧩 Compatibility
- Operating systems: Debian 10/11/12 + , Ubuntu 20.04/22.04+
- Ansible: 2.9 + (the role uses only core modules)
🔒 Security Notes
- Store
samba_admin_passwordin Ansible Vault in production. - The role backs up the Samba configuration to the directory defined by
backup_path– seetasks/logging.ymlfor how the backup is created.
📄 Templates
| Template | Description |
|---|---|
templates/smb.conf.j2 |
Samba configuration for the AD DC |
templates/krb5.conf.j2 |
Kerberos client config |
templates/resolv.conf.j2 |
Static /etc/resolv.conf (search domain + nameserver) |
templates/ntp.conf.j2 |
NTP configuration used by tasks/ntpd.yml |
🛠️ Troubleshooting
| Issue | What to check |
|---|---|
samba-tool domain provision fails with a password error |
Verify samba_admin_password is correct and no‑log (no_log: true) is set. |
| DNS resolution fails on the DC itself | Ensure samba_iface contains lo and the NIC (e.g., lo eth0) and that /etc/resolv.conf is not a symlink. |
| Time skew on the DC | Verify NTP service is running (systemctl status ntp). |
| Backup directory missing | Check that backup_path is writable by the user running the playbook. |
📥 Install via Ansible Galaxy
ansible-galaxy init samba_ad_dc
After adding this file, run:
ansible-galaxy collection install samba_ad_dc
🤝 Contributing
Feel free to submit PRs – just keep the variable documentation in sync with the files you modify. Happy automating!