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 +0,0 @@
H3sVxt9kbuoXGvG

View File

@@ -4,9 +4,6 @@
gather_facts: true gather_facts: true
become: true become: true
collections:
- somaz94.ansible_k8s_iac_tool
tasks: tasks:
# - Update all packages # - Update all packages
# - Install ansible-core # - Install ansible-core
@@ -26,18 +23,21 @@
state: present state: present
become: true become: true
- name: Download terraform - name: Register status of /usr/local/bin/terraform
ansible.builtin.get_url: ansible.builtin.stat:
url: https://releases.hashicorp.com/terraform/terraform_{{ terraform_version }}/terraform_{{ terraform_version }}_{{ ansible_facts.ansible_os_family }}_{{ ansible_facts.ansible_architecture }}.zip path: /usr/local/bin/terraform
dest: /tmp/terraform.zip register: terraform_path
mode: 0755
- name: Install terraform - name: Download and installt erraform version
ansible.builtin.package: when: not terraform_path.stat.exists
name: terraform block:
state: present - name: Download and install terraform
become: true ansible.builtin.unarchive:
src: "https://releases.hashicorp.com/terraform/{{ terraform_version }}/terraform_{{ terraform_version }}_linux_amd64.zip"
dest: "/usr/local/bin/"
remote_src: true
mode: '0755'
exclude: "LICENSE.txt"
roles: roles:
- install_kustomize - somaz94.ansible_k8s_iac_tool.install_kustomize

View File

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

View File

@@ -0,0 +1,11 @@
// Terraform DNS entry template
resource "freeipa_dns_record" "ocp-hub" {
zone_name = "int.mk-labs.cloud."
name = "ocp-hub"
type = "A"
records = [
"10.1.71.10",
]
ttl = 60
}

View File

@@ -0,0 +1,11 @@
// Terraform DNS entry template
resource "freeipa_dns_record" "pve01" {
zone_name = "int.mk-labs.cloud."
name = "pve01"
type = "A"
records = [
"10.1.71.51",
]
ttl = 60
}

11
host_vars/infra01/vars Normal file
View File

@@ -0,0 +1,11 @@
---
# file: host_vars/infra01/vars
# Networking
# primary_interface: "enp1s0f0"
# mac_address: "98:b7:85:1e:c6:f1"
#ip_address: 10.1.71.51
hostname: "infra01.{{ base_domain }}"
# Software
terraform_version: "1.11.3"

View File

@@ -3,12 +3,13 @@
- name: Master playbook for home lab - name: Master playbook for home lab
hosts: all hosts: all
gather_facts: true gather_facts: false
connection: local
# roles:
# - dns-entry
# tasks: tasks:
- name: Process DNS entries
- name: Process DNS entries when: inventory_hostname == "infra01"
ansible.builtin.import_playbook: dns-entry.yml ansible.builtin.import_tasks:
file: dns-entry.yml
tags:
- update-dns
- never

View File

@@ -1,7 +1,7 @@
# Configure the DNS Provider # Configure the DNS Provider
provider "freeipa" { provider "freeipa" {
host = "infra01.int.mk-labs.cloud" host = var.freeipa_server
username = "admin" username = var.freeipa_admin
password = var.freeipa_password password = var.freeipa_password
insecure = true insecure = true
} }

View File

@@ -1,22 +1,26 @@
--- ---
- name: Run all tasks necessary to configure matchbox to install the cluster - name: Run all tasks necessary to configure matchbox to install the cluster
hosts: matchbox hosts: infra01
connection: local #connection: local
gather_facts: true gather_facts: true
tasks: tasks:
- name: Print vars for debugging # - name: Print vars for debugging
ansible.builtin.debug: # ansible.builtin.debug:
msg: System {{ hostvars['infra01'].matchbox_assets }} / {{ hostvars['ocp-hub'].cluster_name }} # msg: System {{ hostvars['infra01'].matchbox_assets }} / {{ hostvars['ocp-hub'].cluster_name }}
- name: Print vars for debugging 2 # - name: Print vars for debugging 2
ansible.builtin.debug: # ansible.builtin.debug:
msg: System {{ groups }} # msg: System {{ groups }}
- name: Print vars for debugging 3 # - name: Print vars for debugging 3
ansible.builtin.debug: # ansible.builtin.debug:
msg: System {{ groups['hub-cluster'][0] }} # msg: System {{ groups['hub-cluster'][0] }}
- name: Print vars for debugging 4 # - name: Print vars for debugging 4
# ansible.builtin.debug:
# msg: System {{ hostvars[groups['hub-cluster'][0]].cluster_name }}
- name: Print all available facts
ansible.builtin.debug: ansible.builtin.debug:
msg: System {{ hostvars[groups['hub-cluster'][0]].cluster_name }} var: ansible_facts