From 7aa8fd5dadc57f9fb7ed667f1e6a4c2853c76c3a Mon Sep 17 00:00:00 2001 From: vchintal Date: Thu, 26 Sep 2019 23:54:22 -0700 Subject: [PATCH] Initial commit --- .gitignore | 4 + setup-ocp-vsphere.yml | 81 ++++++++++++++++ setup-vcenter-vms.yml | 123 +++++++++++++++++++++++++ templates/append-bootstrap-vm-param.j2 | 1 + templates/append-bootstrap.ign.j2 | 18 ++++ templates/install-config.yaml.j2 | 21 +++++ templates/master-vm-param.j2 | 1 + templates/worker-vm-param.j2 | 1 + vars.yml | 19 ++++ 9 files changed, 269 insertions(+) create mode 100644 .gitignore create mode 100644 setup-ocp-vsphere.yml create mode 100644 setup-vcenter-vms.yml create mode 100644 templates/append-bootstrap-vm-param.j2 create mode 100644 templates/append-bootstrap.ign.j2 create mode 100644 templates/install-config.yaml.j2 create mode 100644 templates/master-vm-param.j2 create mode 100644 templates/worker-vm-param.j2 create mode 100644 vars.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d576b18 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +bin +downloads +install-dir +**/*.bak diff --git a/setup-ocp-vsphere.yml b/setup-ocp-vsphere.yml new file mode 100644 index 0000000..350401d --- /dev/null +++ b/setup-ocp-vsphere.yml @@ -0,0 +1,81 @@ +- hosts: localhost + vars: + masterContent: "{{ lookup('file', '{{ playbook_dir }}/install-dir/master.64' )}}" + workerContent: "{{ lookup('file', '{{ playbook_dir }}/install-dir/worker.64' )}}" + appendBootstrapContent: "{{ lookup('file', '{{ playbook_dir }}/install-dir/append-bootstrap.64' )}}" + tasks: + + - name: Create bin, install-dir and downloads folders + file: + path: "{{ playbook_dir }}/{{ item }}" + state: directory + mode: '0755' + with_items: ["bin", "downloads", "install-dir"] + + - name: Download the oc client + get_url: + url: "{{ download.oc_client }}" + dest: "{{ playbook_dir }}/downloads/oc_client.tar.gz" + + - name: Download the openshift-install CLI tool + get_url: + url: "{{ download.openshift_install }}" + dest: "{{ playbook_dir }}/downloads/openshift_install.tar.gz" + + - name: Unarchive oc client + unarchive: + src: "{{ playbook_dir }}/downloads/oc_client.tar.gz" + dest: "{{ playbook_dir }}/bin" + remote_src: yes + + - name: Unarchive openshift-install + unarchive: + src: "{{ playbook_dir }}/downloads/openshift_install.tar.gz" + dest: "{{ playbook_dir }}/bin" + remote_src: yes + + - name: Copy install-config.yaml file into install-dir + template: + src: "{{ playbook_dir }}/templates/install-config.yaml.j2" + dest: "{{ playbook_dir }}/install-dir/install-config.yaml" + + - name: Backup the install-config.yaml file + copy: + src: "{{ playbook_dir }}/install-dir/install-config.yaml" + dest: "{{ playbook_dir }}/install-dir/install-config.yaml.orig" + + - name: Generate the ignition configs + command: "{{ playbook_dir }}/bin/openshift-install create ignition-configs --dir={{ playbook_dir }}/install-dir" + +# - copy: +# src: "{{ playbook_dir }}/install-dir/bootstrap.ign" +# dest: /var/www/html/ignition + + - name: Copy append-bootstrap.ign file into install-dir + template: + src: "{{ playbook_dir }}/templates/append-bootstrap.ign.j2" + dest: "{{ playbook_dir }}/install-dir/append-bootstrap.ign" + + - name: Get base64 version of append-bootstrap.ign + shell: "base64 -w0 {{ playbook_dir }}/install-dir/append-bootstrap.ign > {{ playbook_dir }}/install-dir/append-bootstrap.64" + + - name: Get base64 version of master.ign + shell: "base64 -w0 {{ playbook_dir }}/install-dir/master.ign > {{ playbook_dir }}/install-dir/master.64" + + - name: Get base64 version of worker.ign + shell: "base64 -w0 {{ playbook_dir }}/install-dir/worker.ign > {{ playbook_dir }}/install-dir/worker.64" + + - name: + template: + src: "{{ playbook_dir }}/templates/master-vm-param.j2" + dest: "{{ playbook_dir }}/install-dir/master-vm-param.txt" + + - name: + template: + src: "{{ playbook_dir }}/templates/worker-vm-param.j2" + dest: "{{ playbook_dir }}/install-dir/worker-vm-param.txt" + + - name: + template: + src: "{{ playbook_dir }}/templates/append-bootstrap-vm-param.j2" + dest: "{{ playbook_dir }}/install-dir/append-bootstrap-vm-param.txt" diff --git a/setup-vcenter-vms.yml b/setup-vcenter-vms.yml new file mode 100644 index 0000000..1e082c1 --- /dev/null +++ b/setup-vcenter-vms.yml @@ -0,0 +1,123 @@ +--- +- hosts: localhost + vars: + bootstrapOvfEnvContent : "{{ lookup('file', '{{ playbook_dir }}/install-dir/append-bootstrap-vm-param.txt') }}" + masterOvfEnvContent : "{{ lookup('file', '{{ playbook_dir }}/install-dir/master-vm-param.txt') }}" + workerOvfEnvContent : "{{ lookup('file', '{{ playbook_dir }}/install-dir/worker-vm-param.txt') }}" + bootstrapContent : "{{ lookup('file', '{{ playbook_dir }}/install-dir/append-bootstrap.64') }}" + masterContent : "{{ lookup('file', '{{ playbook_dir }}/install-dir/master.64') }}" + workerContent : "{{ lookup('file', '{{ playbook_dir }}/install-dir/worker.64') }}" + templateName : rhcos-4.1.0-x86_64-vmware + tasks: + - name: "Bootstrap guest.ovfEnv" + debug: + msg: "{{ bootstrapOvfEnvContent }}" + - name: "Master guest.ovfEnv" + debug: + msg: "{{ masterOvfEnvContent }}" + - name: "Worker guest.ovfEnv" + debug: + msg: "{{ workerOvfEnvContent }}" + - name: "Bootstrap base64" + debug: + msg: "{{ bootstrapContent }}" + - name: "Master base64" + debug: + msg: "{{ masterContent }}" + - name: "Worker base64 " + debug: + msg: "{{ workerContent }}" + - name: Create bootstrap VM from the template + vmware_guest: + hostname: "{{ vcenter.ip }}" + username: "{{ vcenter.username }}" + password: "{{ vcenter.password }}" + datacenter: dc + validate_certs: no + folder: /dc/vm/ocp4 + name: bootstrap + state: poweredoff + template: "{{ templateName }}" + disk: + - size_gb: 120 + type: thin + datastore: datastore1 + hardware: + memory_mb: 16384 + num_cpus: 4 + memory_reservation_lock: True + networks: + - name: VM Network + mac: "00:50:56:a8:aa:a1" + wait_for_ip_address: no + customvalues: + - key: guestinfo.ovfEnv + value: "{{ bootstrapOvfEnvContent }}" + - key: guestinfo.ignition.config.data + value: "{{ bootstrapContent }}" + - name: Create master VMs from ther template + vmware_guest: + hostname: "{{ vcenter.ip }}" + username: "{{ vcenter.username }}" + password: "{{ vcenter.password }}" + datacenter: dc + validate_certs: no + folder: /dc/vm/ocp4 + name: "{{ item.name }}" + state: poweredoff + template: "{{ templateName }}" + disk: + - size_gb: 120 + type: thin + datastore: datastore1 + hardware: + memory_mb: 16384 + num_cpus: 4 + memory_reservation_lock: True + networks: + - name: VM Network + mac: "{{ item.mac }}" + wait_for_ip_address: no + customvalues: + - key: guestinfo.ovfEnv + value: "{{ masterOvfEnvContent }}" + - key: guestinfo.ignition.config.data + value: "{{ masterContent }}" + loop: + - { name : "master0", mac: "00:50:56:a8:aa:a2"} + - { name : "master1", mac: "00:50:56:a8:aa:a3"} + - { name : "master2", mac: "00:50:56:a8:aa:a4"} + - name: Create worked VMs from the template + vmware_guest: + hostname: "{{ vcenter.ip }}" + username: "{{ vcenter.username }}" + password: "{{ vcenter.password }}" + datacenter: dc + validate_certs: no + folder: /dc/vm/ocp4 + name: "{{ item.name }}" + state: poweredoff + template: "{{ templateName }}" + disk: + - size_gb: 120 + type: thin + datastore: datastore1 + hardware: + memory_mb: 8192 + num_cpus: 2 + memory_reservation_lock: True + networks: + - name: VM Network + mac: "{{ item.mac }}" + wait_for_ip_address: no + customvalues: + - key: guestinfo.ovfEnv + value: "{{ workerOvfEnvContent }}" + - key: guestinfo.ignition.config.data + value: "{{ workerContent }}" + loop: + - { name : "worker0", mac: "00:50:56:a8:aa:a6"} + - { name : "worker1", mac: "00:50:56:a8:aa:a7"} + - { name : "worker2", mac: "00:50:56:a8:aa:a8"} + + diff --git a/templates/append-bootstrap-vm-param.j2 b/templates/append-bootstrap-vm-param.j2 new file mode 100644 index 0000000..7250162 --- /dev/null +++ b/templates/append-bootstrap-vm-param.j2 @@ -0,0 +1 @@ + diff --git a/templates/append-bootstrap.ign.j2 b/templates/append-bootstrap.ign.j2 new file mode 100644 index 0000000..246cca6 --- /dev/null +++ b/templates/append-bootstrap.ign.j2 @@ -0,0 +1,18 @@ +{ + "ignition": { + "config": { + "append": [ + { + "source": "{{ bootstrap.ignHttpLocation }}", + "verification": {} + } + ] + }, + "timeouts": {}, + "version": "2.1.0" + }, + "networkd": {}, + "passwd": {}, + "storage": {}, + "systemd": {} +} diff --git a/templates/install-config.yaml.j2 b/templates/install-config.yaml.j2 new file mode 100644 index 0000000..ef83e35 --- /dev/null +++ b/templates/install-config.yaml.j2 @@ -0,0 +1,21 @@ +apiVersion: v1 +baseDomain: {{ config.baseDomain }} +compute: +- hyperthreading: Enabled + name: worker + replicas: 0 +controlPlane: + hyperthreading: Enabled + name: master + replicas: 3 +metadata: + name: {{ config.clusterName }} +platform: + vsphere: + vcenter: {{ vcenter.ip }} + username: {{ vcenter.username }} + password: {{ vcenter.password }} + datacenter: {{ vcenter.datacenter }} + defaultDatastore: {{ vcenter.datastore }} +pullSecret: '{{ config.pullSecret | to_json }}' +sshKey: '{{ config.sshKey }}' diff --git a/templates/master-vm-param.j2 b/templates/master-vm-param.j2 new file mode 100644 index 0000000..280bb41 --- /dev/null +++ b/templates/master-vm-param.j2 @@ -0,0 +1 @@ + diff --git a/templates/worker-vm-param.j2 b/templates/worker-vm-param.j2 new file mode 100644 index 0000000..708838f --- /dev/null +++ b/templates/worker-vm-param.j2 @@ -0,0 +1 @@ + diff --git a/vars.yml b/vars.yml new file mode 100644 index 0000000..a571859 --- /dev/null +++ b/vars.yml @@ -0,0 +1,19 @@ +--- +bootstrap: + ignHttpLocation: http://192.168.86.180:8080/ignition/bootstrap.ign +config: + baseDomain: example.com + clusterName: ocp4 + sshKey: ssh-rsa ... + pullSecret: {"auths": ... } +vcenter: + ip: 192.168.86.100 + datastore: datastore1 + username: administrator@vsphere.local + password: Password123! + datacenter: dc +download: + #oc_client: "https://mirror.openshift.com/pub/openshift-v4/clients/ocp-dev-preview/latest/openshift-client-linux-4.2.0-0.nightly-2019-09-25-233506.tar.gz" + #openshift_install: "https://mirror.openshift.com/pub/openshift-v4/clients/ocp-dev-preview/latest/openshift-install-linux-4.2.0-0.nightly-2019-09-25-233506.tar.gz" + oc_client: "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-linux-4.1.16.tar.gz" + openshift_install: "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-install-linux-4.1.16.tar.gz"