diff --git a/10-sno-hub-cluster/03-openshift-image/move-pxe-assets.yml b/10-sno-hub-cluster/03-openshift-image/move-pxe-assets.yml index 1bbfbfd..3b4902f 100644 --- a/10-sno-hub-cluster/03-openshift-image/move-pxe-assets.yml +++ b/10-sno-hub-cluster/03-openshift-image/move-pxe-assets.yml @@ -1,7 +1,7 @@ --- - name: Create a directory if it does not exist ansible.builtin.file: - path: "{{ matchbox_assets }}/{{ hostvars['ocp-hub'].cluster_name }}" + path: "{{ hostvars[groups['matchbox'][0]].matchbox_assets }}/{{ hostvars[groups['hub-cluster'][0]].cluster_name }}" state: directory mode: '0755' become: true @@ -9,7 +9,8 @@ - name: Copy file with owner and permissions ansible.builtin.copy: src: 03-openshift-image/boot-artifacts/ - dest: "{{ matchbox_assets }}/{{ hostvars['ocp-hub'].cluster_name }}/" + dest: "{{ hostvars[groups['matchbox'][0]].matchbox_assets }}/{{ hostvars[groups['hub-cluster'][0]].cluster_name }}/" owner: matchbox group: matchbox + mode: '0644' become: true diff --git a/10-sno-hub-cluster/templates/openshift-installer/agent-config.yaml.j2 b/10-sno-hub-cluster/03-openshift-image/templates/agent-config.yaml.j2 similarity index 87% rename from 10-sno-hub-cluster/templates/openshift-installer/agent-config.yaml.j2 rename to 10-sno-hub-cluster/03-openshift-image/templates/agent-config.yaml.j2 index 186e44d..274608c 100644 --- a/10-sno-hub-cluster/templates/openshift-installer/agent-config.yaml.j2 +++ b/10-sno-hub-cluster/03-openshift-image/templates/agent-config.yaml.j2 @@ -1,9 +1,9 @@ apiVersion: v1alpha1 kind: AgentConfig metadata: - name: {{ hostvars['ocp-hub'].cluster_name }} + name: {{ hostvars[groups['hub-cluster'][0]].cluster_name }} rendezvousIP: {{ hostvars['ocp-hub'].ip_address }} -bootArtifactsBaseURL: https://matchbox.int.mk-labs.cloud:8080/assets/hub/ +bootArtifactsBaseURL: {{ hostvars['matchbox'].http_endpoint }}/assets/hub/ hosts: - hostname: {{ hostvars['ocp-hub'].hostname }} role: master diff --git a/10-sno-hub-cluster/03-openshift-image/templates/install-config.yaml.j2 b/10-sno-hub-cluster/03-openshift-image/templates/install-config.yaml.j2 new file mode 100644 index 0000000..528189c --- /dev/null +++ b/10-sno-hub-cluster/03-openshift-image/templates/install-config.yaml.j2 @@ -0,0 +1,25 @@ +apiVersion: v1 +baseDomain: {{ hostvars[groups['hub-cluster'][0]].base_domain }} +compute: +- name: worker + replicas: {{ hostvars[groups['hub-cluster'][0]].worker_node_count }} +controlPlane: + hyperthreading: Enabled + name: master + replicas: {{ hostvars[groups['hub-cluster'][0]].master_node_count }} +metadata: + name: {{ hostvars[groups['hub-cluster'][0]].cluster_name }} +networking: + clusterNetwork: + - cidr: {{ hostvars[groups['hub-cluster'][0]].cluster_network }} + hostPrefix: {{ hostvars[groups['hub-cluster'][0]].cluster_network_host_prefix }} + machineNetwork: + - cidr: {{ hostvars[groups['hub-cluster'][0]].machine_network }} + networkType: OVNKubernetes + serviceNetwork: + - {{ hostvars[groups['hub-cluster'][0]].service_network }} +platform: + {{ hostvars[groups['hub-cluster'][0]].platform_type }}: {} +fips: false +pullSecret: '{{ vault_pull_secret }}' +sshKey: '{{ vault_ssh_key }}' diff --git a/10-sno-hub-cluster/04-matchbox/templates/groups.tf.j2 b/10-sno-hub-cluster/04-matchbox/templates/groups.tf.j2 new file mode 100644 index 0000000..0889314 --- /dev/null +++ b/10-sno-hub-cluster/04-matchbox/templates/groups.tf.j2 @@ -0,0 +1,8 @@ +// Matcher group for OCP Internal machines +resource "matchbox_group" "{{ hostvars[groups['hub-cluster'][0]].cluster_name }}" { + name = "{{ hostvars['ocp-hub'].hostname }}" # Physical Server + profile = matchbox_profile.openshift-agent-install.name + selector = { + mac = "{{ hostvars['ocp-hub'].mac_address }}" # PXE boots and installs to 10GbE NIC + } +} diff --git a/10-sno-hub-cluster/04-matchbox/templates/profiles.tf.j2 b/10-sno-hub-cluster/04-matchbox/templates/profiles.tf.j2 new file mode 100644 index 0000000..f1acc68 --- /dev/null +++ b/10-sno-hub-cluster/04-matchbox/templates/profiles.tf.j2 @@ -0,0 +1,16 @@ +// Fedora CoreOS profile +resource "matchbox_profile" "openshift-agent-install" { + name = "{{ hostvars[groups['hub-cluster'][0]].cluster_name }}" + kernel = "/assets/{{ hostvars[groups['hub-cluster'][0]].cluster_name }}/agent.x86_64-vmlinuz" + initrd = [ + "--name initrd /assets/{{ hostvars[groups['hub-cluster'][0]].cluster_name }}/agent.x86_64-initrd.img" + ] + + args = [ + "initrd=initrd", + "coreos.live.rootfs_url={{ hostvars['matchbox'].http_endpoint }}/assets/{{ hostvars[groups['hub-cluster'][0]].cluster_name }}/agent.x86_64-rootfs.img", + "rw", + "ignition.firstboot", + "ignition.platform.id=metal", + ] +} diff --git a/10-sno-hub-cluster/templates/matchbox/provider.tf.j2 b/10-sno-hub-cluster/04-matchbox/templates/provider.tf.j2 similarity index 87% rename from 10-sno-hub-cluster/templates/matchbox/provider.tf.j2 rename to 10-sno-hub-cluster/04-matchbox/templates/provider.tf.j2 index b2b17a0..3b46e0a 100644 --- a/10-sno-hub-cluster/templates/matchbox/provider.tf.j2 +++ b/10-sno-hub-cluster/04-matchbox/templates/provider.tf.j2 @@ -1,6 +1,6 @@ // Configure the matchbox provider provider "matchbox" { - endpoint = "{{ matchbox_rpc_endpoint }}" + endpoint = "{{ hostvars['matchbox'].rpc_endpoint }}" client_cert = file("/etc/matchbox/client.crt") client_key = file("/etc/matchbox/client.key") ca = file("/etc/matchbox/ca.crt") diff --git a/10-sno-hub-cluster/install.yml b/10-sno-hub-cluster/install.yml index 4e5d46b..d1e4eef 100644 --- a/10-sno-hub-cluster/install.yml +++ b/10-sno-hub-cluster/install.yml @@ -9,43 +9,51 @@ community.general.terraform: project_path: 01-dns/ variables: - freeipa_password: "{{ freeipa_password }}" + freeipa_password: "{{ vault_freeipa_password }}" state: present force_init: true - - ansible.builtin.include_tasks: + - name: Deploy DHCP entries for cluster via Terraform + ansible.builtin.include_tasks: file: 02-dhcp/ip-reservations.yml - name: OpenShift Installer install-config.yaml ansible.builtin.template: - src: templates/openshift-installer/install-config.yaml.j2 + src: 03-openshift-image/templates/install-config.yaml.j2 dest: 03-openshift-image/install-config.yaml + mode: '0644' - name: OpenShift Installer agent-config.yaml ansible.builtin.template: - src: templates/openshift-installer/agent-config.yaml.j2 + src: 03-openshift-image/templates/agent-config.yaml.j2 dest: 03-openshift-image/agent-config.yaml + mode: '0644' - - ansible.builtin.include_tasks: + - name: Create OpenShift image + ansible.builtin.include_tasks: file: 03-openshift-image/create-openshift-image.yml - - ansible.builtin.include_tasks: + - name: Move PXE assets to matchbox + 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 + src: matchbox/templates/groups.tf.j2 dest: 04-matchbox/groups.tf + mode: '0644' - name: Terraform matchbox profiles file ansible.builtin.template: - src: templates/matchbox/profiles.tf.j2 + src: matchbox/templates/profiles.tf.j2 dest: 04-matchbox/profiles.tf + mode: '0644' - name: Terraform matchbox provider file ansible.builtin.template: - src: templates/matchbox/provider.tf.j2 + src: matchbox/templates/provider.tf.j2 dest: 04-matchbox/provider.tf + mode: '0644' - name: Configure Matchbox via Terraform community.general.terraform: diff --git a/10-sno-hub-cluster/templates/matchbox/groups.tf.j2 b/10-sno-hub-cluster/templates/matchbox/groups.tf.j2 deleted file mode 100644 index 8d445e1..0000000 --- a/10-sno-hub-cluster/templates/matchbox/groups.tf.j2 +++ /dev/null @@ -1,8 +0,0 @@ -// 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/10-sno-hub-cluster/templates/matchbox/profiles.tf.j2 b/10-sno-hub-cluster/templates/matchbox/profiles.tf.j2 deleted file mode 100644 index 7e389d2..0000000 --- a/10-sno-hub-cluster/templates/matchbox/profiles.tf.j2 +++ /dev/null @@ -1,16 +0,0 @@ -// 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/10-sno-hub-cluster/templates/openshift-installer/install-config.yaml.j2 b/10-sno-hub-cluster/templates/openshift-installer/install-config.yaml.j2 deleted file mode 100644 index d31614a..0000000 --- a/10-sno-hub-cluster/templates/openshift-installer/install-config.yaml.j2 +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: v1 -baseDomain: {{ hostvars['ocp-hub'].base_domain }} -compute: -- name: worker - replicas: {{ hostvars['ocp-hub'].worker_node_count }} -controlPlane: - hyperthreading: Enabled - name: master - replicas: {{ hostvars['ocp-hub'].master_node_count }} -metadata: - name: {{ hostvars['ocp-hub'].cluster_name }} -networking: - clusterNetwork: - - cidr: {{ hostvars['ocp-hub'].cluster_network }} - hostPrefix: {{ hostvars['ocp-hub'].cluster_network_host_prefix }} - machineNetwork: - - cidr: {{ hostvars['ocp-hub'].machine_network }} - networkType: OVNKubernetes - serviceNetwork: - - {{ hostvars['ocp-hub'].service_network }} -platform: - {{ hostvars['ocp-hub'].platform_type }}: {} -fips: false -pullSecret: '{{ vault_pull_secret }}' -sshKey: '{{ vault_ssh_key }}' diff --git a/group_vars/freeipa/vars b/group_vars/freeipa/vars index d9ddd8f..49b80a1 100644 --- a/group_vars/freeipa/vars +++ b/group_vars/freeipa/vars @@ -1,3 +1,3 @@ --- freeipa_user: "admin" -freeipa_password: "{{ vault_freeipa_password }}" +#freeipa_password: "{{ vault_freeipa_password }}" diff --git a/group_vars/matchbox/vars b/group_vars/matchbox/vars index dec570c..a4270c6 100644 --- a/group_vars/matchbox/vars +++ b/group_vars/matchbox/vars @@ -1,9 +1,9 @@ --- # 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" +assets: "/var/lib/matchbox/assets" +http_endpoint: "http://matchbox.int.mk-labs.cloud:8080" +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 }}" +#openshift_installer_pull_secret: "{{ vault_pull_secret }}" +#openshift_installer_ssh_key: "{{ vault_ssh_key }}" diff --git a/test.yml b/test.yml new file mode 100644 index 0000000..7c3f184 --- /dev/null +++ b/test.yml @@ -0,0 +1,22 @@ +--- +- name: Run all tasks necessary to configure matchbox to install the cluster + hosts: matchbox + connection: local + gather_facts: true + + 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 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 4 + ansible.builtin.debug: + msg: System {{ hostvars[groups['hub-cluster'][0]].cluster_name }}