Files
homelab/infra-config/dns-entry.yml

45 lines
1.4 KiB
YAML

---
# file: dns-entry.yml
# This playbook is used to create a DNS entry for a given server if it's IP address is a host variable.
# It will create a Terraform file in the homelab/terraform/dns directory.
# It will then run the Terraform apply command to create the DNS entry.
# It will then notify the update-dns handler to update the DNS entry.
# Future work:
# - Add a check to see if the DNS entry already exists.
# - Add a check to see if the Terraform provider is already configured.
# - Add a check to see if the Terraform DNS entry is already created.
- name: Validate Terraform DNS provider
delegate_to: "{{ terraform_server }}"
run_once: true
block:
- name: Check if terraform directory exists
ansible.builtin.stat:
path: homelab/terraform/dns
register: terraform_dir
- name: Create Terraform directory for DNS entries
ansible.builtin.file:
path: homelab/terraform/dns
state: directory
mode: '0755'
when: not terraform_dir.stat.exists
- name: "Create/Update Terraform DNS provider"
ansible.builtin.template:
src: templates/dns_provider.tf.j2
dest: homelab/terraform/dns/provider.tf
mode: '0644'
- name: Create Terraform files for DNS
delegate_to: "{{ terraform_server }}"
ansible.builtin.template:
src: templates/dns.tf.j2
dest: homelab/terraform/dns/{{ inventory_hostname }}.tf
mode: '0644'
changed_when: true
notify:
- Update DNS