45 lines
1.6 KiB
YAML
45 lines
1.6 KiB
YAML
---
|
|
- name: Configure DNS
|
|
block:
|
|
- name: Set FQDNs
|
|
set_fact:
|
|
dns_fqdn: "{{ lookup('community.general.dig', dns_ip + '/PTR') }}"
|
|
vm_fqdn: "{{ vm_name + '.' + namespace }}"
|
|
|
|
- name: Gather DNS hostname and zonename
|
|
set_fact:
|
|
dns_host: "{{ dns_fqdn.split('.')[0] }}"
|
|
zone: "{{ namespace.split('.')[1] + '.' + namespace.split('.')[2] }}"
|
|
|
|
- name: Set DNS host OS
|
|
set_fact:
|
|
dns_os: "{{ hostvars[dns_host]['platforms'][0] }}"
|
|
|
|
- name: Insert DNS record
|
|
ansible.builtin.blockinfile:
|
|
#backup: yes
|
|
block: "{{ lookup('template', '../templates/nsd_zone.j2') }}"
|
|
marker: "; {mark} Ansible managed block for {{ vm_name }}"
|
|
path: "/var/nsd/zones/master/{{ zone }}.zone"
|
|
when: dns_os == 'openbsd-x86_64'
|
|
delegate_to: "{{ dns_host }}"
|
|
|
|
- name: Insert DNS static host mapping
|
|
vyos.vyos.vyos_config:
|
|
backup: yes
|
|
backup_options:
|
|
dir_path: "/tmp/"
|
|
comment: "Configured as part of {{ vm_name }} deployment"
|
|
lines:
|
|
- "set system static-host-mapping host-name {{ vm_fqdn }} inet {{ ip_address }}"
|
|
- "set system static-host-mapping host-name {{ vm_fqdn }} alias {{ vm_name }}"
|
|
save: no # CHANGE BEFORE ROLLOUT
|
|
when: dns_os == 'vyos-x86_64'
|
|
delegate_to: "{{ dns_host }}"
|
|
|
|
always:
|
|
- name: Debug
|
|
ansible.builtin.debug:
|
|
msg: "{{ dns_ip if dns_ip is defined }} - {{ dns_host if dns_host is defined }} - {{ dns_fqdn if dns_fqdn is defined }} - {{ dns_os if dns_os is defined }} - {{ vm_fqdn if vm_fqdn is defined }} - {{ zone if zone is defined }}"
|
|
|