system/ansible/deployment_poc/tasks/configure_dns.yml
Georg Pfuetzenreuter 2ce8450b89
Bulk update
Signed-off-by: Georg Pfuetzenreuter <georg@lysergic.dev>
2022-02-13 16:56:12 +01:00

57 lines
1.8 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 }}"
tags:
- init_ssh
- 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: Reload DNS zone
ansible.builtin.command:
argv:
- /usr/bin/doas
- nsd-control
- reload
- "{{ zone }}"
when: dhcp_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 }}"