summaryrefslogtreecommitdiffstats
path: root/ansible/deployment_poc/tasks/configure_dns.yml
blob: 9a2880064c39322ac97bad020c596ba13770a601 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
- 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 }}"