@@ -2,9 +2,7 @@
|
|||||||
- name: Install all software on infra01
|
- name: Install all software on infra01
|
||||||
hosts: infra01
|
hosts: infra01
|
||||||
gather_facts: true
|
gather_facts: true
|
||||||
|
become: true
|
||||||
collections:
|
|
||||||
- somaz94.ansible_k8s_iac_tool
|
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
# - Update all packages
|
# - Update all packages
|
||||||
@@ -19,12 +17,27 @@
|
|||||||
state: present
|
state: present
|
||||||
become: true
|
become: true
|
||||||
|
|
||||||
# - name: Clone Git repository
|
- name: Install dnf-plugins-core
|
||||||
# ansible.builtin.git:
|
ansible.builtin.package:
|
||||||
# repo: "https://github.com/rblundon/homelab.git"
|
name: dnf-plugins-core
|
||||||
# dest: ~
|
state: present
|
||||||
# version: deploy-hub-cluster #main
|
become: true
|
||||||
# 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:
|
roles:
|
||||||
- install_kustomize
|
- somaz94.ansible_k8s_iac_tool.install_kustomize
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ This implementation is built on easily accessible consumer based hardware and wi
|
|||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
|
- Ansible user created
|
||||||
|
- Ansible configured
|
||||||
- [Networking](docs/networks.md)
|
- [Networking](docs/networks.md)
|
||||||
- [Proxmox](docs/proxmox.md) (In my homelab, internal DNS, identity manangement, and ipxe are hosted here.)
|
- [Proxmox](docs/proxmox.md) (In my homelab, internal DNS, identity manangement, and ipxe are hosted here.)
|
||||||
- Matchbox
|
- Matchbox
|
||||||
|
|||||||
54
dns-entry.yml
Normal file
54
dns-entry.yml
Normal file
@@ -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
|
||||||
59
frr-openshift.conf
Normal file
59
frr-openshift.conf
Normal file
@@ -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
|
||||||
|
!
|
||||||
@@ -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"
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
---
|
---
|
||||||
freeipa_user: "admin"
|
#freeipa_user: "admin"
|
||||||
#freeipa_password: "{{ vault_freeipa_password }}"
|
#freeipa_password: "{{ vault_freeipa_password }}"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
cluster_name: "hub"
|
cluster_name: "hub"
|
||||||
cluster_version: "4.17.20"
|
cluster_version: "4.17.20"
|
||||||
base_domain: "int.mk-labs.cloud"
|
#base_domain: "int.mk-labs.cloud"
|
||||||
worker_node_count: 0
|
worker_node_count: 0
|
||||||
master_node_count: 1
|
master_node_count: 1
|
||||||
cluster_network: "10.128.0.0/14"
|
cluster_network: "10.128.0.0/14"
|
||||||
11
host_vars/infra01/vars
Normal file
11
host_vars/infra01/vars
Normal 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"
|
||||||
6
host_vars/pve01/vars
Normal file
6
host_vars/pve01/vars
Normal file
@@ -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"
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
|
# file: inventory.yml
|
||||||
proxmox:
|
proxmox:
|
||||||
hosts:
|
hosts:
|
||||||
pve01:
|
pve0[1:3]:
|
||||||
pve02:
|
|
||||||
pve03:
|
|
||||||
|
|
||||||
freeipa:
|
freeipa:
|
||||||
hosts:
|
hosts:
|
||||||
@@ -12,6 +11,6 @@ matchbox:
|
|||||||
hosts:
|
hosts:
|
||||||
infra01:
|
infra01:
|
||||||
|
|
||||||
hub-cluster:
|
hub_cluster:
|
||||||
hosts:
|
hosts:
|
||||||
ocp-hub:
|
ocp-hub:
|
||||||
|
|||||||
14
print_ips.yml
Normal file
14
print_ips.yml
Normal file
@@ -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
|
||||||
2
proxmox.yml
Normal file
2
proxmox.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
# file: proxmox.yml
|
||||||
15
site.yml
Normal file
15
site.yml
Normal file
@@ -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
|
||||||
11
templates/dns.tf.j2
Normal file
11
templates/dns.tf.j2
Normal file
@@ -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
|
||||||
|
}
|
||||||
32
templates/dns_provider.tf.j2
Normal file
32
templates/dns_provider.tf.j2
Normal file
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
40
test.yml
40
test.yml
@@ -1,22 +1,32 @@
|
|||||||
---
|
---
|
||||||
- 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: all
|
||||||
connection: local
|
#connection: local
|
||||||
gather_facts: true
|
gather_facts: false
|
||||||
|
|
||||||
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:
|
# ansible.builtin.debug:
|
||||||
msg: System {{ hostvars[groups['hub-cluster'][0]].cluster_name }}
|
# 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
|
||||||
Reference in New Issue
Block a user