Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vchintal committed Sep 27, 2019
0 parents commit 7aa8fd5
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin
downloads
install-dir
**/*.bak
81 changes: 81 additions & 0 deletions setup-ocp-vsphere.yml
Original file line number Diff line number Diff line change
@@ -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"
123 changes: 123 additions & 0 deletions setup-vcenter-vms.yml
Original file line number Diff line number Diff line change
@@ -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"}


1 change: 1 addition & 0 deletions templates/append-bootstrap-vm-param.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Environment oe:id="" xmlns="http://schemas.dmtf.org/ovf/environment/1" xmlns:oe="http://schemas.dmtf.org/ovf/environment/1" xmlns:ve="http://www.vmware.com/schema/ovfenv" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><PropertySection><Property oe:key="guestinfo.ignition.config.data" oe:value="{{ appendBootstrapContent}}"/><Property oe:key="guestinfo.ignition.config.data.encoding" oe:value="base64"/></PropertySection></Environment>
18 changes: 18 additions & 0 deletions templates/append-bootstrap.ign.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"ignition": {
"config": {
"append": [
{
"source": "{{ bootstrap.ignHttpLocation }}",
"verification": {}
}
]
},
"timeouts": {},
"version": "2.1.0"
},
"networkd": {},
"passwd": {},
"storage": {},
"systemd": {}
}
21 changes: 21 additions & 0 deletions templates/install-config.yaml.j2
Original file line number Diff line number Diff line change
@@ -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 }}'
1 change: 1 addition & 0 deletions templates/master-vm-param.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Environment oe:id="" xmlns="http://schemas.dmtf.org/ovf/environment/1" xmlns:oe="http://schemas.dmtf.org/ovf/environment/1" xmlns:ve="http://www.vmware.com/schema/ovfenv" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><PropertySection><Property oe:key="guestinfo.ignition.config.data" oe:value="{{ masterContent }}"/><Property oe:key="guestinfo.ignition.config.data.encoding" oe:value="base64"/></PropertySection></Environment>
1 change: 1 addition & 0 deletions templates/worker-vm-param.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Environment oe:id="" xmlns="http://schemas.dmtf.org/ovf/environment/1" xmlns:oe="http://schemas.dmtf.org/ovf/environment/1" xmlns:ve="http://www.vmware.com/schema/ovfenv" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><PropertySection><Property oe:key="guestinfo.ignition.config.data" oe:value="{{ workerContent }}"/><Property oe:key="guestinfo.ignition.config.data.encoding" oe:value="base64"/></PropertySection></Environment>
19 changes: 19 additions & 0 deletions vars.yml
Original file line number Diff line number Diff line change
@@ -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: [email protected]
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"

0 comments on commit 7aa8fd5

Please sign in to comment.