Skip to content

Commit

Permalink
Reconcile the latest AI changes for remote workers
Browse files Browse the repository at this point in the history
With the latest changes from AI, we are able to specify
the network using nmstate files. We also can
generate the images using AI.

Signed-off-by: Yolanda Robla <[email protected]>
  • Loading branch information
Yolanda Robla authored and serngawy committed Mar 18, 2021
1 parent 28fca37 commit df92f19
Show file tree
Hide file tree
Showing 18 changed files with 245 additions and 468 deletions.
20 changes: 8 additions & 12 deletions ai-deploy-cluster-remoteworker/inventory/hosts.sample
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,15 @@ pull_secret='xxx'
# ssh key of the installer machine
ssh_public_key="ssh-rsa xxx"

# Default as httpd config
ignition_http_server_path=/var/www/html
kernel_arguments=""
ai_iso_path=/opt/cached_disconnected_images

# You can set your own rootfs image and store it under the same IP as above.
#rootfs_url=https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/4.6/latest/rhcos-live-rootfs.x86_64.img

# should be same as the installer machine IP-address
ai_url="http://192.168.112.199:8080"
ignition_url="http://192.168.112.199"
iso_url="http://192.168.112.199"

# You will need to configure your env DNS server for the cluster_domain and cluster_name
cluster_name="test-aut"
cluster_domain="cluster.testing"
cluster_version="4.7"
cluster_sdn="OpenShiftSDN" # if not set, defaults to OVNKubernetes
#cluster_sdn="OpenShiftSDN" # if not set, defaults to OVNKubernetes

# Make sure api_vip is mapped in your env DNS server to api.{cluster_name}.{cluster_domain} AND ingress_vip to *.apps.{cluster_name}.{cluster_domain}
ingress_vip=192.168.112.195
Expand All @@ -38,6 +29,10 @@ temporary_path=/tmp

# optional: path where to store images for controlplane
# libvirt_images_path=/var/lib/libvirt/images
#
# network configuration, in nmstate format. Please enable
# that if you need to rely on static ip configuration
#network_config_path=./samples/worker.yaml

[provisioner]
# host from where the installation is performed
Expand All @@ -50,5 +45,6 @@ master_2 name=master_2 mac_address=52:54:00:55:f3:32
master_3 name=master_3 mac_address=52:54:00:55:f3:33

[worker_nodes]
worker-0.test-aut.cluster-testing name=worker_0 bmc_type=SuperMicro bmc_address=192.168.111.212 bmc_user="ADMIN" bmc_password="ADMIN" smb_host=192.168.111.1 smb_path=share ramdisk_path=/opt/network-config kernel_arguments="" final_iso_path=/home/share/ redeploy=false profile=worker-cnf
worker-1 bmc_type=Dell name=worker_1 bmc_address=10.16.231.121 bmc_user="usr" bmc_password="pwd" ramdisk_path=/opt/network-config kernel_arguments="" final_iso_path=/opt/cached_disconnected_images redeploy=false
# only set ip if you need to embed static network. It needs to match with the nmstate config
worker-0.test-aut.cluster-testing name=worker_0 bmc_type=SuperMicro bmc_address=192.168.111.212 bmc_user="ADMIN" bmc_password="ADMIN" smb_host=192.168.111.1 smb_path=share ip=<host_ip> hostname=<hostname> redeploy=false profile=worker-cnf
worker-1 bmc_type=Dell name=worker_1 bmc_address=10.16.231.121 bmc_user="usr" bmc_password="pwd"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
---
- name: Enroll all remote workers
include_tasks: add_remote_worker.yaml
- name: Enroll a SuperMicro node
include_role:
name: "{{ playbook_dir }}/../common-roles/enroll-supermicro"
vars:
iso_name: "{{ cluster_name }}-day2.iso"
smb_host: "{{ hostvars[item].smb_host }}"
smb_path: "{{ hostvars[item].smb_path }}"
bmc_address: "{{ hostvars[item].bmc_address }}"
bmc_user: "{{ hostvars[item].bmc_user }}"
bmc_password: "{{ hostvars[item].bmc_password }}"
when: hostvars[item].bmc_type == "SuperMicro"
with_items: "{{ groups['worker_nodes'] }}"

- name: Enroll a Dell node
include_role:
name: "{{ playbook_dir }}/../common-roles/enroll-dell"
vars:
iso_name: "{{ cluster_name }}-day2.iso"
bmc_user: "{{ hostvars[item].bmc_user }}"
bmc_password: "{{ hostvars[item].bmc_password }}"
bmc_address: "{{ hostvars[item].bmc_address }}"
iso_url: "{{ hostvars[item].iso_url }}"
when: hostvars[item].bmc_type == "Dell"
with_items: "{{ groups['worker_nodes'] }}"

- name: Wait until hosts are ready in Assisted Installer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
---
- name: Create a temporary file
tempfile:
state: file
register: tempfile_pullsecret

- name: Copy pull secret to file
copy:
content: "{{ pull_secret }}"
dest: "{{ tempfile_pullsecret.path }}"

- name: Create cluster and download ISO
block:
- name: Create new AI cluster
shell: "aicli create cluster -P pull_secret={{ tempfile_pullsecret.path }} -P base_dns_domain={{ cluster_domain }} -P ssh_public_key='{{ ssh_public_key }}' -P openshift_version='{{ cluster_version }}' {{ cluster_name }}-day2"

- name: Generate the ISO for the cluster
shell: "aicli create iso -P ssh_public_key='{{ ssh_public_key }}' {{ cluster_name }}-day2"

- name: And download it
shell: "aicli download iso {{ cluster_name }}-day2 -p {{ temporary_path }}"

environment:
AI_URL: "{{ ai_url }}"

- name: create day 2 cluster
include_role:
name: "{{ playbook_dir }}/../common-roles/create-cluster"
vars:
extra_args: "-P ingress_vip={{ ingress_vip }}"
cluster_name_var: "{{ cluster_name }}-day2"
60 changes: 13 additions & 47 deletions ai-deploy-cluster-remoteworker/roles/create-cluster/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,14 @@
---
- name: Create a temporary file
tempfile:
state: file
register: tempfile_pullsecret

- name: Copy pull secret to file
copy:
content: "{{ pull_secret }}"
dest: "{{ tempfile_pullsecret.path }}"

- name: Create cluster and download ISO
block:
- name: Create new AI cluster
shell: "aicli create cluster -P pull_secret={{ tempfile_pullsecret.path }} -P base_dns_domain={{ cluster_domain }} -P ssh_public_key='{{ ssh_public_key }}' -P ingress_vip={{ ingress_vip }} -P openshift_version='{{ cluster_version }}' {{ cluster_name }}"
retries: 30
delay: 5
register: result
until: result.rc == 0

- name: Retrieve cluster ID from name
shell: "aicli list cluster | grep {{ cluster_name }} | cut -d '|' -f3 | tr -d ' '"
register: cluster_id

- name: Set the right network type
uri:
url: "{{ ai_url }}/api/assisted-install/v1/clusters/{{ cluster_id.stdout }}/install-config"
method: PATCH
body: '"{\"networking\": {\"networkType\": \"{{ cluster_sdn | default("OVNKubernetes") }}\"}}"'
body_format: json
status_code: 201

- name: Generate the ISO for the cluster
shell: "aicli create iso -P ssh_public_key='{{ ssh_public_key }}' {{ cluster_name }}"
retries: 30
delay: 5
register: result
until: result.rc == 0

- name: And download it
shell: "aicli download iso {{ cluster_name }} -p {{ temporary_path }}"
retries: 3
delay: 3
register: result
until: result.rc == 0
environment:
AI_URL: "{{ ai_url }}"

- name: create cluster
include_role:
name: "{{ playbook_dir }}/../common-roles/create-cluster"
vars:
extra_args: "-P ingress_vip={{ ingress_vip }}"
cluster_name_var: "{{ cluster_name }}"

- name: download ISO
include_role:
name: "{{ playbook_dir }}/../common-roles/download-iso"
vars:
cluster_name_var: "{{ cluster_name }}"
final_iso_path_var: "{{ temporary_path }}"
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
---
- name: Configure cluster
block:
- name: Update host to copy the network
shell: "aicli update host $(aicli list hosts | grep {{ cluster_name }} | grep {{ item }} | awk '{print $6}') -P extra_args=[--copy-network]"
- name: Update hostnames
shell: "IP=$(aicli list hosts | grep {{ cluster_name }}-day2 | grep {{ hostvars[item].ip }} | cut -d '|' -f 4 | tr -d ' '); aicli update host $IP -P name={{ hostvars[item].hostname }}"
when: hostvars[item].hostname is defined and hostvars[item].hostname|length > 0
with_items: "{{ groups['worker_nodes'] }}"

- name: For each worker, override the default mcp if it has a profile
shell: "aicli update host $(aicli list hosts | grep {{ cluster_name }} | grep {{ item }} | awk '{print $6}') -P mcp={{ hostvars[item].profile }}"
when: hostvars[item].profile is defined
shell: "IP=$(aicli list hosts | grep {{ cluster_name }}-day2 | grep {{ hostvars[item].hostname }} | cut -d '|' -f 4 | tr -d ' '); aicli update host $IP -P mcp={{ hostvars[item].profile }}"
when: hostvars[item].profile is defined and hostvars[item].profile|length > 0 and hostvars[item].hostname is defined and hostvars[item].hostname|length > 0
with_items: "{{ groups['worker_nodes'] }}"

- name: Install cluster
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<domain type='kvm'>
<name>{{ hostvars[item].name }}_{{ cluster_name }}</name>
<memory unit='KiB'>17008000</memory>
<currentMemory unit='KiB'>17008000</currentMemory>
<memory unit='KiB'>18008000</memory>
<currentMemory unit='KiB'>18008000</currentMemory>
<vcpu placement='static'>4</vcpu>
<os>
<type arch='x86_64' machine='pc-i440fx-rhel7.6.0'>hvm</type>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,8 @@
---
- name: Create temporary directory for script
tempfile:
state: directory
register: script_directory

- name: Get the script to modify ISOs
get_url:
url: https://raw.githubusercontent.com/redhat-ztp/ztp-iso-generator/main/rhcos-iso/inject_config_files.sh
dest: "{{ script_directory.path }}/inject_config_files.sh"
mode: 0755

- name: Get the script to generate ramdisk
get_url:
url: https://raw.githubusercontent.com/redhat-ztp/ztp-iso-generator/main/rhcos-iso/ramdisk_generator.sh
dest: "{{ script_directory.path }}/ramdisk_generator.sh"
mode: 0755

- name: Get the script to extract ignition from ISO
get_url:
url: https://raw.githubusercontent.com/redhat-ztp/ztp-iso-generator/main/rhcos-iso/extract_ignition_from_ai_iso.sh
dest: "{{ script_directory.path }}/extract_ignition_from_ai_iso.sh"
mode: 0755

- name: Create temporary directory for modifying the ignition
tempfile:
state: directory
register: ignition_directory

- name: Extract the ignition file from the downloaded ISO
shell:
chdir: "{{ script_directory.path }}"
cmd: "{{ script_directory.path }}/extract_ignition_from_ai_iso.sh {{ temporary_path }}/{{ cluster_name }}-day2.iso {{ ignition_directory.path }}/ai_ignition"

- name: Modify ISO for all the workers
include_tasks: modify_iso_for_worker.yaml
with_items: "{{ groups['worker_nodes'] }}"
- name: Generate ISOs for the workers
include_role:
name: "{{ playbook_dir }}/../common-roles/download-iso"
vars:
cluster_name_var: "{{ cluster_name }}-day2"
minimal: True
final_iso_path_var: "{{ final_iso_path }}"
Loading

0 comments on commit df92f19

Please sign in to comment.