diff --git a/03-infra01-server/install.yml b/03-infra01-server/install.yml index 7098b4c..d855c15 100644 --- a/03-infra01-server/install.yml +++ b/03-infra01-server/install.yml @@ -2,9 +2,7 @@ - name: Install all software on infra01 hosts: infra01 gather_facts: true - - collections: - - somaz94.ansible_k8s_iac_tool + become: true tasks: # - Update all packages @@ -19,12 +17,27 @@ state: present become: true - # - name: Clone Git repository - # ansible.builtin.git: - # repo: "https://github.com/rblundon/homelab.git" - # dest: ~ - # version: deploy-hub-cluster #main - # become: true + - name: Install dnf-plugins-core + ansible.builtin.package: + name: dnf-plugins-core + state: present + become: true + + - name: Register status of /usr/local/bin/terraform + ansible.builtin.stat: + path: /usr/local/bin/terraform + register: terraform_path + + - name: Download and installt erraform version + when: not terraform_path.stat.exists + block: + - name: Download and install terraform + 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: - - install_kustomize + - somaz94.ansible_k8s_iac_tool.install_kustomize diff --git a/README.md b/README.md index 42c5e17..79741cb 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ This implementation is built on easily accessible consumer based hardware and wi ## Prerequisites +- Ansible user created +- Ansible configured - [Networking](docs/networks.md) - [Proxmox](docs/proxmox.md) (In my homelab, internal DNS, identity manangement, and ipxe are hosted here.) - Matchbox diff --git a/dns-entry.yml b/dns-entry.yml new file mode 100644 index 0000000..05fe52c --- /dev/null +++ b/dns-entry.yml @@ -0,0 +1,54 @@ +--- +# file: dns-entry.yml + +- 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: Loop through all hosts + vars: + my_hosts: "{{ query('inventory_hostnames', 'all') }}" + # ansible.builtin.debug: + # msg: "Host {{ item }} has IP address: {{ hostvars[my_hosts[my_idx]].ip_address | default('No IP address defined') }}" + ansible.builtin.template: + src: templates/dns.tf.j2 + dest: homelab/terraform/dns/{{ item }}.tf + mode: '0644' + when: hostvars[my_hosts[my_idx]].ip_address is defined + loop: "{{ my_hosts }}" + loop_control: + index_var: my_idx + +# - 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 diff --git a/frr-openshift.conf b/frr-openshift.conf new file mode 100644 index 0000000..3083b1d --- /dev/null +++ b/frr-openshift.conf @@ -0,0 +1,59 @@ +! +frr version 8.1 +frr defaults traditional +hostname WorldDrive +domainname int.mk-labs.cloud +log syslog informational +service integrated-vtysh-config +! +router bgp 65002 + bgp router-id 10.1.71.1 + bgp log-neighbor-changes + no bgp default ipv4-unicast + neighbor internal peer-group + neighbor internal remote-as 65001 + neighbor external peer-group + neighbor external remote-as 65003 + neighbor 10.1.71.141 peer-group external + neighbor 10.1.71.141 description Compact1 + neighbor 10.1.71.142 peer-group external + neighbor 10.1.71.142 description Compact2 + neighbor 10.1.71.143 peer-group external + neighbor 10.1.71.143 description Compact3 + neighbor 10.1.71.131 peer-group internal + neighbor 10.1.71.131 description MF 3 + neighbor 10.1.71.132 peer-group internal + neighbor 10.1.71.132 description NUC2 + neighbor 10.1.71.133 peer-group internal + neighbor 10.1.71.133 description NUC3 + neighbor 10.1.71.134 peer-group internal + neighbor 10.1.71.134 description MF 3 + neighbor 10.1.71.135 peer-group internal + neighbor 10.1.71.135 description NUC2 + neighbor 10.1.71.136 peer-group internal + neighbor 10.1.71.136 description NUC3 + ! + address-family ipv4 unicast + ! no need to redistribute connected, as we are not advertising our own routes + ! redistribute connected + neighbor external activate + neighbor external soft-reconfiguration inbound + neighbor external route-map allow-external in + neighbor internal activate + neighbor internal soft-reconfiguration inbound + neighbor internal route-map allow-internal in + exit-address-family +exit +! +! allow any advertised routes in this range with up to 32 bits mask length +ip prefix-list external seq 5 permit 10.1.182.0/24 le 32 +ip prefix-list internal seq 5 permit 10.1.82.0/24 le 32 +! +route-map allow-external permit 10 + match ip address prefix-list external +exit +! +route-map allow-internal permit 10 + match ip address prefix-list internal +exit +! \ No newline at end of file diff --git a/group_vars/all/vars b/group_vars/all/vars index ed97d53..c91009f 100644 --- a/group_vars/all/vars +++ b/group_vars/all/vars @@ -1 +1,7 @@ --- +# file: group_vars/all + +# DNS variables +dns_server: "infra01.int.mk-labs.cloud" +dns_admin: "admin" +base_domain: "int.mk-labs.cloud" \ No newline at end of file diff --git a/group_vars/freeipa/vars b/group_vars/freeipa/vars index 49b80a1..8a5cebd 100644 --- a/group_vars/freeipa/vars +++ b/group_vars/freeipa/vars @@ -1,3 +1,3 @@ --- -freeipa_user: "admin" +#freeipa_user: "admin" #freeipa_password: "{{ vault_freeipa_password }}" diff --git a/group_vars/hub-cluster/vars b/group_vars/hub_cluster/vars similarity index 87% rename from group_vars/hub-cluster/vars rename to group_vars/hub_cluster/vars index 3c45e44..2928cfd 100644 --- a/group_vars/hub-cluster/vars +++ b/group_vars/hub_cluster/vars @@ -1,6 +1,6 @@ cluster_name: "hub" cluster_version: "4.17.20" -base_domain: "int.mk-labs.cloud" +#base_domain: "int.mk-labs.cloud" worker_node_count: 0 master_node_count: 1 cluster_network: "10.128.0.0/14" diff --git a/host_vars/infra01/vars b/host_vars/infra01/vars new file mode 100644 index 0000000..be95983 --- /dev/null +++ b/host_vars/infra01/vars @@ -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" diff --git a/host_vars/pve01/vars b/host_vars/pve01/vars new file mode 100644 index 0000000..8159029 --- /dev/null +++ b/host_vars/pve01/vars @@ -0,0 +1,6 @@ +--- +# file: host_vars/pve01/vars +# mac_address: "98:b7:85:1e:c6:f1" +ip_address: "10.1.71.51" +hostname: "pve01.{{ base_domain }}" +# primary_interface: "enp1s0f0" \ No newline at end of file diff --git a/inventory.yml b/inventory.yml index 2122fd7..e568817 100644 --- a/inventory.yml +++ b/inventory.yml @@ -1,8 +1,7 @@ +# file: inventory.yml proxmox: hosts: - pve01: - pve02: - pve03: + pve0[1:3]: freeipa: hosts: @@ -12,6 +11,6 @@ matchbox: hosts: infra01: -hub-cluster: +hub_cluster: hosts: ocp-hub: diff --git a/print_ips.yml b/print_ips.yml new file mode 100644 index 0000000..1f3921a --- /dev/null +++ b/print_ips.yml @@ -0,0 +1,14 @@ +--- +- name: Print host IP addresses + hosts: infra01 + gather_facts: false + vars: + my_hosts: "{{ query('inventory_hostnames', 'all') }}" + tasks: + - name: Loop through all hosts + ansible.builtin.debug: + msg: "Host {{ item }} has IP address: {{ hostvars[my_hosts[my_idx]].ip_address | default('No IP address defined') }}" + when: hostvars[my_hosts[my_idx]].ip_address is defined + loop: "{{ my_hosts }}" + loop_control: + index_var: my_idx diff --git a/proxmox.yml b/proxmox.yml new file mode 100644 index 0000000..0f741cf --- /dev/null +++ b/proxmox.yml @@ -0,0 +1,2 @@ +--- +# file: proxmox.yml diff --git a/site.yml b/site.yml new file mode 100644 index 0000000..a134ac5 --- /dev/null +++ b/site.yml @@ -0,0 +1,15 @@ +--- +# file: site.yml + +- name: Master playbook for home lab + hosts: all + gather_facts: false + + tasks: + - name: Process DNS entries + when: inventory_hostname == "infra01" + ansible.builtin.import_tasks: + file: dns-entry.yml + tags: + - update-dns + - never diff --git a/templates/dns.tf.j2 b/templates/dns.tf.j2 new file mode 100644 index 0000000..dd07de8 --- /dev/null +++ b/templates/dns.tf.j2 @@ -0,0 +1,11 @@ +// Terraform DNS entry template + +resource "freeipa_dns_record" "{{ inventory_hostname }}" { + zone_name = "{{ base_domain }}." + name = "{{ inventory_hostname }}" + type = "A" + records = [ + "{{ hostvars[inventory_hostname].ip_address }}", + ] + ttl = 60 +} diff --git a/templates/dns_provider.tf.j2 b/templates/dns_provider.tf.j2 new file mode 100644 index 0000000..e137942 --- /dev/null +++ b/templates/dns_provider.tf.j2 @@ -0,0 +1,32 @@ +# Configure the DNS Provider +provider "freeipa" { + host = var.freeipa_server + username = var.freeipa_admin + password = var.freeipa_password + insecure = true +} + +variable "freeipa_server" { + description = "The server for the FreeIPA provider" + type = string +} + +variable "freeipa_admin" { + description = "The admin username for the FreeIPA provider" + type = string +} + +variable "freeipa_password" { + description = "The password for the FreeIPA provider" + type = string + sensitive = true +} + +terraform { + required_providers { + freeipa = { + source = "rework-space-com/freeipa" + version = "5.0.0" + } + } +} diff --git a/test.yml b/test.yml index 7c3f184..da29d64 100644 --- a/test.yml +++ b/test.yml @@ -1,22 +1,32 @@ --- - name: Run all tasks necessary to configure matchbox to install the cluster - hosts: matchbox - connection: local - gather_facts: true + hosts: all + #connection: local + gather_facts: false tasks: - - name: Print vars for debugging - ansible.builtin.debug: - msg: System {{ hostvars['infra01'].matchbox_assets }} / {{ hostvars['ocp-hub'].cluster_name }} + # - name: Print vars for debugging + # ansible.builtin.debug: + # msg: System {{ hostvars['infra01'].matchbox_assets }} / {{ hostvars['ocp-hub'].cluster_name }} - - name: Print vars for debugging 2 - ansible.builtin.debug: - msg: System {{ groups }} + # - name: Print vars for debugging 2 + # ansible.builtin.debug: + # msg: System {{ groups }} - - name: Print vars for debugging 3 - ansible.builtin.debug: - msg: System {{ groups['hub-cluster'][0] }} + # - name: Print vars for debugging 3 + # ansible.builtin.debug: + # msg: System {{ groups['hub-cluster'][0] }} - - name: Print vars for debugging 4 - ansible.builtin.debug: - msg: System {{ hostvars[groups['hub-cluster'][0]].cluster_name }} + # - 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: + # var: ansible_facts + + + - name: Print host IP address if defined + debug: + msg: "Host {{ inventory_hostname }} has IP address: {{ hostvars[inventory_hostname].ip_address | default('Not defined') }}" + when: hostvars[inventory_hostname].ip_address is defined \ No newline at end of file