145 lines
5.2 KiB
YAML
145 lines
5.2 KiB
YAML
---
|
|
- name: Generate custom ISO file for deploying OKD to baremetal
|
|
hosts: all
|
|
connection: local
|
|
gather_facts: no
|
|
|
|
vars:
|
|
#okdVersion: "4.15.0-0.okd-2024-03-10-010116"
|
|
okdVersion: "4.16.0-okd-scos.1"
|
|
|
|
tempDir: "/tmp/ocp-baremetal-iso-staging"
|
|
machineNetwork: "10.1.14.0/24"
|
|
baseDomain: "endofday.com"
|
|
clusterName: "snoballs"
|
|
sshKey: "ssh-rsa "
|
|
bootDisk: "/dev/sda"
|
|
|
|
#binariesBaseUrl: "https://github.com/okd-project/okd/releases/download"
|
|
binariesBaseUrl: "https://github.com/okd-project/okd-scos/releases/download"
|
|
#binariesBaseUrl: "https://cdn.endofday.com/okd-project/okd-scos/releases/download"
|
|
|
|
#scosBaseUrl: "https://cdn.endofday.com/okd-project"
|
|
scosBaseUrl: ""
|
|
useCustomButaneTemplates: false
|
|
|
|
tasks:
|
|
- name: Ensure staging directory exists
|
|
ansible.builtin.file:
|
|
path: "{{ tempDir }}/{{ clusterName }}"
|
|
state: directory
|
|
|
|
- name: Check if binaries exist
|
|
ansible.builtin.stat:
|
|
path: "{{ tempDir }}/{{ item }}"
|
|
register: binaries
|
|
with_items:
|
|
- "openshift-install"
|
|
- "oc"
|
|
|
|
- name: Download and extract binaries
|
|
when: >
|
|
(binaries.results | map(attribute='stat.exists') | select('equalto', false) | list | length) > 0
|
|
block:
|
|
- name: Download OKD Binaries
|
|
ansible.builtin.get_url:
|
|
url: "{{ binariesBaseUrl }}/{{ okdVersion }}/{{ item }}-{{ okdVersion }}.tar.gz"
|
|
dest: "{{ tempDir }}/{{ item }}-{{ okdVersion }}.tar.gz"
|
|
with_items:
|
|
- "openshift-client-linux"
|
|
- "openshift-install-linux"
|
|
|
|
- name: Extract openshift binaries
|
|
ansible.builtin.unarchive:
|
|
src: "{{ tempDir }}/{{ item }}-{{okdVersion}}.tar.gz"
|
|
dest: "{{ tempDir }}"
|
|
with_items:
|
|
- "openshift-client-linux"
|
|
- "openshift-install-linux"
|
|
|
|
- name: Ensure the extracted binaries are executable
|
|
ansible.builtin.file:
|
|
path: "{{ tempDir }}/{{ item }}"
|
|
state: file
|
|
mode: '0755'
|
|
with_items:
|
|
- kubectl
|
|
- oc
|
|
- openshift-install
|
|
|
|
- name: Remove binary tarballs
|
|
ansible.builtin.file:
|
|
path: "{{ tempDir }}/{{ item }}-{{okdVersion}}.tar.gz"
|
|
state: absent
|
|
with_items:
|
|
- "openshift-client-linux"
|
|
- "openshift-install-linux"
|
|
|
|
- name: Create install-config.yaml file
|
|
ansible.builtin.template:
|
|
src: "templates/install-config.yaml.j2"
|
|
dest: "{{ tempDir }}/{{ clusterName }}/install-config.yaml"
|
|
mode: "0644"
|
|
|
|
- name: Generate the install manifests (if butane is required)
|
|
when: useCustomButaneTemplates == true
|
|
block:
|
|
- name: Generate stock manifests
|
|
ansible.builtin.shell: |
|
|
set -o pipefail
|
|
{{ tempDir }}/openshift-install create manifests --dir={{ tempDir }}/{{ clusterName }}
|
|
register: generate_ignition_manifests
|
|
changed_when: false
|
|
|
|
- name: Create butane templates
|
|
ansible.builtin.template:
|
|
src: "{{ item }}"
|
|
dest: "{{ tempDir }}/{{ item | basename | regex_replace('\\.j2$', '') }}"
|
|
with_fileglob:
|
|
- templates/*.bu.j2
|
|
|
|
- name: Render butane template to OpenShift manifest
|
|
ansible.builtin.shell: |
|
|
set -o pipefail
|
|
butane {{ tempDir }}/{{ item|basename }} -o {{ tempDir }}/{{ clusterName }}/openshift/{{ item | basename | regex_replace('\\.bu', '.yaml') }}
|
|
with_fileglob:
|
|
- "{{ tempDir }}/*.bu"
|
|
register: render_butane_template
|
|
changed_when: false
|
|
|
|
- name: Generate ignition config for single node
|
|
ansible.builtin.shell: |
|
|
set -o pipefail
|
|
{{ tempDir }}/openshift-install create single-node-ignition-config --dir={{ tempDir }}/{{ clusterName }}
|
|
register: generate_ignition_file
|
|
|
|
- name: Check if ISO image exists
|
|
ansible.builtin.stat:
|
|
path: "{{ tempDir }}/os.iso"
|
|
register: iso
|
|
|
|
- name: Download CoreOS ISO
|
|
when: iso.stat.exists == false
|
|
block:
|
|
|
|
- name: Get CentOS Stream CoreOS ISO download location from openshift-installer
|
|
ansible.builtin.shell: |
|
|
set -o pipefail
|
|
{{ tempDir }}/openshift-install coreos print-stream-json | grep location | grep x86_64 | grep iso | cut -d\" -f4
|
|
register: scos_image_url
|
|
|
|
- name: Download ISO
|
|
ansible.builtin.get_url:
|
|
url: "{{ (scosBaseUrl | d('') != '') | ternary( scos_image_url.stdout | regex_replace( 'https://builds.coreos.fedoraproject.org/prod/streams/stable/builds', scosBaseUrl), scos_image_url.stdout) }}"
|
|
dest: "{{ tempDir }}/os.iso"
|
|
|
|
- name: Embed the ignition bootstrap into the iso image
|
|
become: true
|
|
ansible.builtin.shell: |
|
|
set -o pipefail
|
|
alias coreos-installer='sudo podman run --privileged --pull always --rm -v /dev:/dev -v /run/udev:/run/udev -v {{ tempDir }}:/data -w /data quay.io/coreos/coreos-installer:release'
|
|
coreos-installer iso ignition embed -fi {{ clusterName }}/bootstrap-in-place-for-live-iso.ign os.iso
|
|
register: embed_ignition_in_iso
|
|
|
|
|