From 79d23cf5d991ec56a482463dbb881d6e6a506529 Mon Sep 17 00:00:00 2001 From: rblundon Date: Sun, 23 Mar 2025 00:55:30 -0500 Subject: [PATCH] create templates for terraform files --- .../README.md | 0 .../agent-config.yaml | 2 +- .../create-openshift-image.yml | 2 +- .../move-pxe-assets.yml | 2 +- 10-sno-hub-cluster/install.yml | 29 +++- group_vars/all/vars | 12 +- group_vars/all/vault | 158 +++++++++++++++++- group_vars/hub/vars | 9 + step-by-step.md | 5 + templates/matchbox/groups.tf.j2 | 8 + templates/matchbox/profiles.tf.j2 | 16 ++ templates/matchbox/provider.tf.j2 | 20 +++ .../install-config.yaml.j2 | 25 +++ .../03-matchbox => tmp}/groups.tf | 0 .../03-matchbox => tmp}/install-config.yaml | 0 .../03-matchbox => tmp}/profiles.tf | 0 .../03-matchbox => tmp}/provider.tf | 0 .../03-matchbox => tmp}/terraform.tfvars | 0 .../03-matchbox => tmp}/variables.tf | 0 19 files changed, 272 insertions(+), 16 deletions(-) rename 10-sno-hub-cluster/{03-matchbox => 03-openshift-image}/README.md (100%) rename 10-sno-hub-cluster/{03-matchbox => 03-openshift-image}/agent-config.yaml (98%) rename 10-sno-hub-cluster/{03-matchbox => 03-openshift-image}/create-openshift-image.yml (81%) rename 10-sno-hub-cluster/{03-matchbox => 03-openshift-image}/move-pxe-assets.yml (89%) create mode 100644 group_vars/hub/vars create mode 100644 templates/matchbox/groups.tf.j2 create mode 100644 templates/matchbox/profiles.tf.j2 create mode 100644 templates/matchbox/provider.tf.j2 create mode 100644 templates/openshift-installer/install-config.yaml.j2 rename {10-sno-hub-cluster/03-matchbox => tmp}/groups.tf (100%) rename {10-sno-hub-cluster/03-matchbox => tmp}/install-config.yaml (100%) rename {10-sno-hub-cluster/03-matchbox => tmp}/profiles.tf (100%) rename {10-sno-hub-cluster/03-matchbox => tmp}/provider.tf (100%) rename {10-sno-hub-cluster/03-matchbox => tmp}/terraform.tfvars (100%) rename {10-sno-hub-cluster/03-matchbox => tmp}/variables.tf (100%) diff --git a/10-sno-hub-cluster/03-matchbox/README.md b/10-sno-hub-cluster/03-openshift-image/README.md similarity index 100% rename from 10-sno-hub-cluster/03-matchbox/README.md rename to 10-sno-hub-cluster/03-openshift-image/README.md diff --git a/10-sno-hub-cluster/03-matchbox/agent-config.yaml b/10-sno-hub-cluster/03-openshift-image/agent-config.yaml similarity index 98% rename from 10-sno-hub-cluster/03-matchbox/agent-config.yaml rename to 10-sno-hub-cluster/03-openshift-image/agent-config.yaml index e3c43fb..ed5122d 100644 --- a/10-sno-hub-cluster/03-matchbox/agent-config.yaml +++ b/10-sno-hub-cluster/03-openshift-image/agent-config.yaml @@ -3,7 +3,7 @@ kind: AgentConfig metadata: name: hub rendezvousIP: 10.1.71.10 -bootArtifactsBaseURL: https://matchbox.int.mk-labs.cloud:8080/assets/sno-hub/ +bootArtifactsBaseURL: https://matchbox.int.mk-labs.cloud:8080/assets/hub/ hosts: - hostname: hub role: master diff --git a/10-sno-hub-cluster/03-matchbox/create-openshift-image.yml b/10-sno-hub-cluster/03-openshift-image/create-openshift-image.yml similarity index 81% rename from 10-sno-hub-cluster/03-matchbox/create-openshift-image.yml rename to 10-sno-hub-cluster/03-openshift-image/create-openshift-image.yml index 575eb00..c01c43e 100644 --- a/10-sno-hub-cluster/03-matchbox/create-openshift-image.yml +++ b/10-sno-hub-cluster/03-openshift-image/create-openshift-image.yml @@ -2,4 +2,4 @@ - name: OpenShift image creation ansible.builtin.command: /usr/local/bin/openshift-install agent create pxe-files args: - chdir: 03-matchbox + chdir: 03-openshift-image diff --git a/10-sno-hub-cluster/03-matchbox/move-pxe-assets.yml b/10-sno-hub-cluster/03-openshift-image/move-pxe-assets.yml similarity index 89% rename from 10-sno-hub-cluster/03-matchbox/move-pxe-assets.yml rename to 10-sno-hub-cluster/03-openshift-image/move-pxe-assets.yml index fe761fd..5ba21be 100644 --- a/10-sno-hub-cluster/03-matchbox/move-pxe-assets.yml +++ b/10-sno-hub-cluster/03-openshift-image/move-pxe-assets.yml @@ -8,7 +8,7 @@ - name: Copy file with owner and permissions ansible.builtin.copy: - src: 03-matchbox/boot-artifacts/ + src: 03-openshift-image/boot-artifacts/ dest: "{{ matchbox_assets }}/{{ hub_cluster_name }}/" owner: matchbox group: matchbox diff --git a/10-sno-hub-cluster/install.yml b/10-sno-hub-cluster/install.yml index 019ed4c..86a1985 100644 --- a/10-sno-hub-cluster/install.yml +++ b/10-sno-hub-cluster/install.yml @@ -16,14 +16,35 @@ - ansible.builtin.include_tasks: file: 02-dhcp/ip-reservations.yml - - ansible.builtin.include_tasks: - file: 03-matchbox/create-openshift-image.yml + - name: Terraform matchbox groups file + ansible.builtin.template: + src: templates/openshift-installer/install-config.yaml.j2 + dest: 03-openshift-image/install-config.yaml + include_vars: group_vars/hub - ansible.builtin.include_tasks: - file: 03-matchbox/move-pxe-assets.yml + file: 03-openshift-image/create-openshift-image.yml + + - ansible.builtin.include_tasks: + file: 03-openshift-image/move-pxe-assets.yml + + - name: Terraform matchbox groups file + ansible.builtin.template: + src: templates/matchbox/groups.tf.j2 + dest: 04-matchbox/groups.tf + + - name: Terraform matchbox profiles file + ansible.builtin.template: + src: templates/matchbox/profiles.tf.j2 + dest: 04-matchbox/profiles.tf + + - name: Terraform matchbox provider file + ansible.builtin.template: + src: templates/matchbox/provider.tf.j2 + dest: 04-matchbox/provider.tf - name: Configure Matchbox via Terraform community.general.terraform: - project_path: 03-matchbox/ + project_path: 04-matchbox/ state: present force_init: true diff --git a/group_vars/all/vars b/group_vars/all/vars index 3cc7426..eb9f134 100644 --- a/group_vars/all/vars +++ b/group_vars/all/vars @@ -5,9 +5,15 @@ freeipa_password: "{{ vault_freeipa_password }}" # Variables for Matchbox matchbox_assets: "/var/lib/matchbox/assets" +matchbox_http_endpoint: "http://matchbox.int.mk-labs.cloud:8080" +matchbox_rpc_endpoint: "matchbox.int.mk-labs.cloud:8081" + +# Variables for OpenShift Installer +openshift_installer_pull_secret: "{{ vault_pull_secret }}" +openshift_installer_ssh_key: "{{ vault_ssh_key }}" # Variables for 10-sno-hub-cluster -mac_address: "98:b7:85:1e:c6:f1" -ip_address: "10.1.71.10" -hostname: "ocp-hub" +hub_cluster_mac_address: "98:b7:85:1e:c6:f1" +hub_cluster_ip_address: "10.1.71.10" +hub_cluster_hostname: "ocp-hub" hub_cluster_name: "hub" diff --git a/group_vars/all/vault b/group_vars/all/vault index 9fbe4c0..06981a1 100644 --- a/group_vars/all/vault +++ b/group_vars/all/vault @@ -1,7 +1,153 @@ $ANSIBLE_VAULT;1.1;AES256 -66333237373037343133313262646464353636633036383862353132313734626533326536643561 -6430343766306631346664306135626637613064376331370a353464353861343337666337306434 -38313138376133623362363935366233636265323936373138323736656438613233336232383762 -3935653063396436360a303566333932343161643064363663373634633432663234336461353265 -61633534646132626531373466343937656138643737393566613063366639326134396137653437 -6132393536353736373965663431633361636361326638666364 +62613938303261383832663164346364363732633639343461316162616131613937373963626531 +6361613835343335353437336364653636613166366265360a386361376332306265366162633633 +64666665643261303665363433343564346638356664373938653432363634343162633133386436 +3532376566333234650a626164333462666265366264303362333136306432663463353565313164 +30646331663964396433303061613561393363393936303538613531643130653633323633616435 +36303865636630353233346661616334306435666134353338643565393761326237313365373734 +37333232386530353336333934326662363630646564356566646263353534633038383338653830 +63303061343430646332623339643931623535363230663535663566346535303232336332326538 +36353161393138323532333135626436633562656565353762633061336537643166616630613364 +34386563656134343363393931333037333862646237356262323432376536346632353361313832 +64646139653139623331353737363132636633376437636136366430386131626230653463313434 +36316430346233346533383039316532623834333339336563613934313239353038386636303537 +38393361373931353830313437303662323633396138346561653038623631626161643639666437 +30653365316165386433336466323530346562393239323933313937636161393936323733643364 +31356638373834616337393733353237356466303538653330646166666564356139623033323739 +36393431366637326136656233336333333563303535336337306639373462663630353032353832 +62626235383264636635393661343537346330393133653432333435366262303036343332363934 +31326135326131636464363266343563326464356662353965366365323236353635626230646439 +36643036343530386432333131393534383765306366666234373737616563623561636534313339 +39343363653161306365626261333561663134323561613234613161303838333531303032363339 +61663930646632663265393836613766383231663839323234613138343130363237373763653632 +33303537393136303738626665303465616564626633313632616131326562613561386436323339 +38306464663066386134386235616237663237613161373834383533666137393931386262653461 +35316366393165373933623638373232623663303361336365613434633935393737383964373862 +63636464363033393763336663633162643733653238336463613836353533386439623063353238 +37383363333331643863313362313162323539316237646264366634366533316436666137356264 +62356461623935636165623937333565613262656332323862366231646232666162386633353535 +39613938326266323561363636363530303031373532346362333539633164346430633938386561 +65646164333037373862313339313238323435656638353833363338383833633438326234623733 +63666539653461323066643061653366653632613738306264386631313362656534613066373831 +31366561623134663436393162366231326633653638323662666336663961363639616534383930 +64643434633038373638386362613236656230346465653036646233363738336664636538366334 +38306538323362393065643538393030306334333036313465666638343064393430623962306233 +30333661666131616561376466373739333130356238643133616533643639643665373330616564 +36376439376536643334366463633333376232363736623238333235663563333362656363613030 +35333536373433643234336631393939313131623934303535623430623063323830316265383131 +33366130383733623561383831393238623335373862393138363832633762646266353061623830 +61656132313830316333623265386161376534383737623731303064663738316465396666376465 +34386465636235343338393038316132333961313934633330613437653838386532336464333266 +37383466623461306532373037663237303839623836336161303462663933653737373266623165 +34396539313331633039663762393338636339636330626630633465326565636138313333666637 +31333431356138336263313434376239366133636137626661613061366532386165623361333032 +31323931653134333566333666383130623833303335666139396338333062356638386434393763 +35333735373564393232386634313735653239343864393839333063383161643837323133623133 +33373661356235633966323532653937646333663361303136313533663535313236653432326535 +62323735363735656431623634383565363863383663393936653232303161663565363962636362 +31376334653332323432613038336238383633363563643733323564313035303366623732306630 +63653531623933333731396432663766663430336661373531333466666365653364663031343561 +31393837313361303132613837613234366639363035346639303738323362373464376266393630 +61323132326435653631653932393663326434343562653666303738376430326539373265653237 +30346466353030306566323363346237373866666232653762323264313162616539303839333132 +33313938653136363530303036613963656161616632343737303031626139353265376537393039 +38303063613934363530316530323463663038386262633530653735323632346139343334306630 +64373939643463626137653363343532396133613261376163306465353030646464623764313862 +36306538366636393237613539316562386638303839343234376437303663313130363335663131 +62306236386165363662393838363536613661333530303864323562656330356634376237303131 +66363063633766656266393136373137353030346333623435366664303834653435663830353465 +37623666663633613939303731313932323339313230623036316665653839383430376433326230 +33656538363264336639636530663463646465313165643434613739373839306335666230343131 +36616265633962353831363533373237653230376438653634336435333130663362363339313039 +38393362396634333964626437653338643639393831326139656531373366356562636262373035 +61386332626334643562626535386333643763643762663533356530316633313134353363653535 +64663663343865366262623363383064613961653235373563363233643562323232666333666632 +32356133656632626236643031653061613164656563663164653264313061363036353966353739 +31383463306562356636343566653039373063336362356366336434303163336535633539666532 +34333233303631616636323338333939643964376663643237663034336637346166306136396431 +64396338393637323639306636376334333338316334353964663431386637663464646632346632 +65343462653938663231333461316131343036303462336232616666393832343263343234636438 +31383830363135373231313464373964313565383638616464303561396630303263653662313134 +39343766613339373766346438313261613631373763623931316639316137653964393930303532 +37373863636364613065373035363765633061383564633136616530363864363935663638633061 +30333139613136636432306436323931613864316535666633383837353565366663346562656666 +64323130386538386633633366623836633162623731326339336232383236656261666338623564 +66366464323934643032386433303832303537323433653739376262346134316566623435303236 +64343938616662623466646132386436313932346439343639356436323238343830323335623734 +37663563356639353562386430303634383539643434393830333838343838303439623033393765 +62316662336233346263616434636331623636393361326139643032313130356261353634623634 +38346237323064613261633465666634376335626331343566353836633635383663306566346236 +39346164373564643062633536643666386362666330663163633063333262326638616532326331 +30303639373230336630323461316364613766613866363764653939316431383133333738656565 +31663565323533343232373930366231393130643630663266613164303964333235393032323536 +31323837393133633338313130653466633264393033353437373036393238663832353537316365 +61653732636539336261326366323034353566363138393438313761663635313531643234373465 +39306435623733306535376439383937616530326662633863313032343437316662613564613636 +64366636376534303931306231633536323133616634623565333839343534346361333462353366 +37343330363537616664666436386330383561323334666334623863333266376432326161373561 +62333761623361316266313536623862623436306231356230383862653232323431313338383738 +36396633623166393735343332353766333634336566303832613630626538323264636134636134 +35663537613163333965343034653038323937626661616136663861313430303036616330303939 +34643235633566663662306363313266353630316365323031363865633536313637393733653233 +31346462643530626336323534653830356131646566623633646136346562373862353564633864 +64323739306134353661613634396332646165366336383030393631663062356362636266326666 +65643938613236633034366264626334333461386533363537323536393133623064613730333433 +39303331363936316564396263326161393035643035326363393362613265366139323833366437 +66613639306336373633393130303537376434376136316331383062373361323630653965653338 +34376563616361313137633038353139366438303733323039656335663136303862663932363835 +35326662663739376635323131646637643133613061383565396462383032346162356237343331 +63393261393230396637383539663162333435326236313632316562643064633232343364356362 +37656639643866663363333964623734656366386530326337623463663461393664666564333334 +64366433653762306330323764623834353865313538616334376532336566653632636233626139 +66326163363533633963663763373163666439346130383236316332656363663063393466303138 +39373536656331303833633135623961376136616461393362313763616661613639316632613166 +31326332393166356563386432313136383763623633643864343331616364313531383763316536 +35303362666263623835396662633138616238306361633034626464333965643039386566333863 +33636433633431663463326535386463626133643662363935663264613730666639366433663938 +36393032303536343330306334326535633262663537636364616466623561333837646535666638 +32376466646566666464393266363438616661356130633763383961633339323334643062653064 +35386539643836663161313634666131383234623436656539373839656635626231373864633438 +63353633613866626239313137303438656362366435666438653635383532323539643237396463 +37623539376638633333363131393232316536353662663138336238653030343039316261656135 +33626531663038326231396663613239353662623937323866333661386633623963643062343330 +31333334373164613764613435343036396534363230333335636631623563626439666535356663 +30633930396533333166613563646231623735373764623937383732323362613437646636316239 +30633930616537313966643464613933386539333033646431336561323236643939373430396533 +65363766346534323962366233393165343439653430633435653637366132643866366537656462 +33316534623466363462333234396562343839666637663661636665303163316536373531353034 +31643735343134666262373864323232646333343337363065336531356533636637323332323361 +66303331316536333839613036663232316365663737323539616537373437326261353862663239 +61656134353834376438623363663837373333653337323636643863656332663564313231333161 +64386561663831633237306233383338333236336532393439646364376233666461663039393739 +35393931633231343730653932646538643862666330373132633764376532373134303732616162 +38643730376131333762303862313663656161666365303934653363633939333966313462343066 +61663762346466343439396430633432653765346134653834653762653435333662363536336235 +65363132656366313838653266633961643536326433623734376238633935633635353336356331 +61356533353561633137333339633930323632366539616139343263653936636563373161316165 +63306161366362616331363962393935316133336337613839616434633835313833663636633365 +30366663396539343238383234633339353230383535636465346634366230643065653731626235 +38653730646530303435616539343661313137333837343264393763333539303537386435316630 +64333039353763393435623932323661353632343634376334376165613637396263386634363064 +37376462393665346233373434336462653763613164616338643433663230353336663666333434 +62623865363764306664336632636339303337346163393763336639646431386366326364653232 +35613638626332623864343932336236393538613761373530376239316665333732376537396334 +37633064303138326532616339386536363238376630363434383636633966656363373530616264 +66653938643031316237666261336661656539353332386230623166356537366165373139386334 +63343737343764323762393162653234356465353565376634333962643434643436636337613132 +63616266366665633932613062363865633031366361313664393138653263333863653338316566 +62373839653334376565613538646233663939303466336165646239393137373831316438383235 +35366539383664666164383431363135323332663134313830633633303034663434636166373362 +62303161656135346563303332376533633635393665393332303861646661386565376562303336 +33366532306130313039376264376232333832303933346265363632383936346439373232623266 +34383131396536663866366661633964656463343431343731313866666638626461646264333637 +61313562363837616263393131313933363335643162343337666563653536353736363261306433 +30353865663837313839336132383137633861636465663930353863303564383561393166356364 +30343263636433666430336164333666633735393932646661353636396634373837356635356332 +31313331393562626265353761663666396263383833333130306465393639636433393339616630 +32646333346561323339616536376564626161633063393663653362343332353962383433376534 +38303966663461303866636632343665306562303364333031663163356233396130386434653735 +66393634303365363839323339353931393234623164643961663864643937323761363734313832 +37393466346461653734656336336430643765363964393239353336633461613733333032356533 +66363563323930393636316465623530643638313663396266636130626233616331623534363064 +65333137343539363432653735623964326231376334393661623335373931613264343261323030 +65613265663933616666 diff --git a/group_vars/hub/vars b/group_vars/hub/vars new file mode 100644 index 0000000..f05c9db --- /dev/null +++ b/group_vars/hub/vars @@ -0,0 +1,9 @@ +cluster_name: "hub" +base_domain: "int.mk-labs.cloud" +worker_node_count: 0 +master_node_count: 1 +cluster_network: "10.128.0.0/14" +cluster_network_host_prefix: 23 +machine_network: "10.1.71.0/24" +service_network: "172.30.0.0/16" +platform_type: "none" diff --git a/step-by-step.md b/step-by-step.md index 893654e..9220c5c 100644 --- a/step-by-step.md +++ b/step-by-step.md @@ -61,6 +61,11 @@ This ~~is~~ *will be* the complete walkthrough of the deployment of my homelab. - 03-matchbox/install-config - 03-matchbox/agent-config + - 03-matchbox/variables.tf + - 03-matchbox/provider.tf + - 03-matchbox/terraform.tfvars + - 03-matchbox/groups.tf + - 03-matchbox/profiles.tf ```bash cd homelab diff --git a/templates/matchbox/groups.tf.j2 b/templates/matchbox/groups.tf.j2 new file mode 100644 index 0000000..8d445e1 --- /dev/null +++ b/templates/matchbox/groups.tf.j2 @@ -0,0 +1,8 @@ +// Matcher group for OCP Internal machines +resource "matchbox_group" "{{hub_cluster_name}}" { + name = "{{hub_cluster_hostname}}" # Physical Server + profile = matchbox_profile.openshift-agent-install.name + selector = { + mac = "{{hub_cluster_mac_address}}" # PXE boots and installs to 10GbE NIC + } +} diff --git a/templates/matchbox/profiles.tf.j2 b/templates/matchbox/profiles.tf.j2 new file mode 100644 index 0000000..7e389d2 --- /dev/null +++ b/templates/matchbox/profiles.tf.j2 @@ -0,0 +1,16 @@ +// Fedora CoreOS profile +resource "matchbox_profile" "openshift-agent-install" { + name = "{{ hub_cluster_name }}" + kernel = "/assets/{{ hub_cluster_name }}/agent.x86_64-vmlinuz" + initrd = [ + "--name initrd /assets/{{ hub_cluster_name }}/agent.x86_64-initrd.img" + ] + + args = [ + "initrd=initrd", + "coreos.live.rootfs_url={{ matchbox_http_endpoint }}/assets/{{ hub_cluster_name }}/agent.x86_64-rootfs.img", + "rw", + "ignition.firstboot", + "ignition.platform.id=metal", + ] +} diff --git a/templates/matchbox/provider.tf.j2 b/templates/matchbox/provider.tf.j2 new file mode 100644 index 0000000..b2b17a0 --- /dev/null +++ b/templates/matchbox/provider.tf.j2 @@ -0,0 +1,20 @@ +// Configure the matchbox provider +provider "matchbox" { + endpoint = "{{ matchbox_rpc_endpoint }}" + client_cert = file("/etc/matchbox/client.crt") + client_key = file("/etc/matchbox/client.key") + ca = file("/etc/matchbox/ca.crt") +} + +terraform { + required_providers { + ct = { + source = "poseidon/ct" + version = "0.13.0" + } + matchbox = { + source = "poseidon/matchbox" + version = "0.5.4" + } + } +} diff --git a/templates/openshift-installer/install-config.yaml.j2 b/templates/openshift-installer/install-config.yaml.j2 new file mode 100644 index 0000000..ee4d87c --- /dev/null +++ b/templates/openshift-installer/install-config.yaml.j2 @@ -0,0 +1,25 @@ +apiVersion: v1 +baseDomain: {{ base_domain }} +compute: +- name: worker + replicas: {{ worker_node_count }} +controlPlane: + hyperthreading: Enabled + name: master + replicas: {{ master_node_count }} +metadata: + name: {{ cluster_name }} +networking: + clusterNetwork: + - cidr: {{ cluster_network }} + hostPrefix: {{ cluster_network_host_prefix }} + machineNetwork: + - cidr: {{ machine_network }} + networkType: OVNKubernetes + serviceNetwork: + - {{ service_network }} +platform: + {{ platform_type }}: {} +fips: false +pullSecret: {{ vault_pull_secret }} +sshKey: {{ vault_ssh_key }} diff --git a/10-sno-hub-cluster/03-matchbox/groups.tf b/tmp/groups.tf similarity index 100% rename from 10-sno-hub-cluster/03-matchbox/groups.tf rename to tmp/groups.tf diff --git a/10-sno-hub-cluster/03-matchbox/install-config.yaml b/tmp/install-config.yaml similarity index 100% rename from 10-sno-hub-cluster/03-matchbox/install-config.yaml rename to tmp/install-config.yaml diff --git a/10-sno-hub-cluster/03-matchbox/profiles.tf b/tmp/profiles.tf similarity index 100% rename from 10-sno-hub-cluster/03-matchbox/profiles.tf rename to tmp/profiles.tf diff --git a/10-sno-hub-cluster/03-matchbox/provider.tf b/tmp/provider.tf similarity index 100% rename from 10-sno-hub-cluster/03-matchbox/provider.tf rename to tmp/provider.tf diff --git a/10-sno-hub-cluster/03-matchbox/terraform.tfvars b/tmp/terraform.tfvars similarity index 100% rename from 10-sno-hub-cluster/03-matchbox/terraform.tfvars rename to tmp/terraform.tfvars diff --git a/10-sno-hub-cluster/03-matchbox/variables.tf b/tmp/variables.tf similarity index 100% rename from 10-sno-hub-cluster/03-matchbox/variables.tf rename to tmp/variables.tf