mirror of
https://github.com/dredx/prole.git
synced 2026-09-23 11:03:59 +00:00
All samba-tool dns commands were using -P (machine account Kerberos) which
silently failed with no error — tasks reported changed=0 but records were
never written. Switch to -U Administrator --password={{ samba_dns_admin_pass }}
which uses the vault-protected admin credentials that were already defined
but never wired up.
Also fix regex patterns in record parsers: samba-tool output uses `A: IP`
and `PTR: fqdn` format, not `A IP` / `PTR fqdn` (space-separated), so
updated regex_findall patterns to match `TYPE:\s+value`.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
49 lines
2.2 KiB
YAML
49 lines
2.2 KiB
YAML
---
|
|
- name: Determine zone and record name
|
|
ansible.builtin.set_fact:
|
|
samba_target_zone: "{{ 'internal.' ~ prole_domain if item.fqdn.endswith('.internal.' ~ prole_domain) or item.fqdn == 'internal.' ~ prole_domain else prole_domain }}"
|
|
samba_dns_record_name: >-
|
|
{% set fqdn_clean = item.fqdn | regex_replace('\\.?$', '') %}
|
|
{% if fqdn_clean == ('internal.' ~ prole_domain if item.fqdn.endswith('.internal.' ~ prole_domain) or item.fqdn == 'internal.' ~ prole_domain else prole_domain) %}
|
|
@
|
|
{% else %}
|
|
{{ fqdn_clean | regex_replace('\\.' ~ (('internal.' ~ prole_domain if item.fqdn.endswith('.internal.' ~ prole_domain) or item.fqdn == 'internal.' ~ prole_domain else prole_domain) | regex_escape) ~ '$', '') }}
|
|
{% endif %}
|
|
|
|
- name: Query existing CNAME records
|
|
ansible.builtin.command:
|
|
cmd: samba-tool dns query {{ samba_dns_server }} {{ samba_target_zone }} {{ samba_dns_record_name }} CNAME
|
|
-U Administrator --password={{ samba_dns_admin_pass }}
|
|
register: cname_query
|
|
changed_when: false
|
|
failed_when: false
|
|
|
|
- name: Parse existing CNAME record value
|
|
ansible.builtin.set_fact:
|
|
cname_existing_value: >-
|
|
{{
|
|
(cname_query.stdout | default('') |
|
|
regex_findall('\\bCNAME:\\s+([a-zA-Z0-9.-]+)\\b') |
|
|
first | default(''))
|
|
}}
|
|
|
|
- name: Remove stale CNAME record
|
|
ansible.builtin.command:
|
|
cmd: samba-tool dns delete {{ samba_dns_server }} {{ samba_target_zone }} {{ samba_dns_record_name }} CNAME {{ cname_existing_value }}
|
|
-U Administrator --password={{ samba_dns_admin_pass }}
|
|
when:
|
|
- cname_existing_value | length > 0
|
|
- cname_existing_value != item.target
|
|
|
|
- name: Add missing CNAME record
|
|
ansible.builtin.command:
|
|
cmd: samba-tool dns add {{ samba_dns_server }} {{ samba_target_zone }} {{ samba_dns_record_name }} CNAME {{ item.target }}
|
|
-U Administrator --password={{ samba_dns_admin_pass }}
|
|
register: cname_add
|
|
changed_when: cname_add.rc == 0
|
|
failed_when: >
|
|
cname_add.rc != 0 and
|
|
('WERR_DNS_ERROR_RECORD_ALREADY_EXISTS' not in (cname_add.stderr | default(''))) and
|
|
('Record already exists' not in (cname_add.stderr | default('')))
|
|
when: cname_existing_value != item.target
|