goodnight

This commit is contained in:
2025-03-27 00:32:02 -05:00
parent ddd5bfc3ac
commit bda585fcd5
9 changed files with 116 additions and 73 deletions

View File

@@ -1,40 +1,46 @@
---
# file: dns-entry.yml
- name: Master playbook for home lab
hosts: all
gather_facts: false
tasks:
- name: Create DNS entry for {{ inventory_hostname }}
when: ip_address is defined
delegate_to: "{{ dns_server }}"
block:
- name: Check if terraform directory exists
ansible.builtin.stat:
path: ~/homelab/terraform/dns
register: terraform_dir
- 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 Terraform directory for DNS entries
ansible.builtin.file:
path: homelab/terraform/dns
state: directory
mode: '0755'
when: not terraform_dir.stat.exists
- name: Create Terraform file for host
ansible.builtin.template:
src: templates/dns.tf.j2
dest: ~/homelab/terraform/dns/{{ inventory_hostname }}.tf
mode: '0644'
- name: "Create/Update Terraform DNS provider"
ansible.builtin.template:
src: templates/dns_provider.tf.j2
dest: homelab/terraform/dns/provider.tf
mode: '0644'
handlers:
- name: Update DNS entries via Terraform
delegate_to: "{{ dns_server }}"
community.general.terraform:
project_path: ~/homelab/terraform/dns/
variables:
freeipa_server: "{{ dns_server }}"
freeipa_admin: "{{ dns_admin }}"
freeipa_password: "{{ vault_freeipa_password }}"
state: present
force_init: true
- name: Show all the hosts in the inventory
when: "{{ hostvars[groups['all'][ {{ item }} ]['ip_address'] }}" is defined
ansible.builtin.debug:
msg: "{{ hostvars[item].ip_address }}"
loop: "{{ query('inventory_hostnames', 'all') }}"
# - name: Loop through all hosts
# block:
# - name: Create Terraform files for all eligible hosts
# when: "{{hostvars["{{ item }}"].ip_address}}" is defined
# ansible.builtin.template:
# src: templates/dns.tf.j2
# dest: homelab/terraform/dns/{{ item }}.tf
# mode: '0644'
# loop: "{{ query('inventory_hostnames', 'all') }}"
# - name: Update DNS entries via Terraform
# community.general.terraform:
# project_path: homelab/terraform/dns/
# variables:
# freeipa_server: "{{ dns_server }}"
# freeipa_admin: "{{ dns_admin }}"
# freeipa_password: "{{ vault_freeipa_password }}"
# state: present
# force_init: true