feat: Remove node-template hypervisor upload logic (treat as prerequisite instead)
Some checks failed
Container & Helm chart / Linting (push) Successful in 6s
Container & Helm chart / Semantic Release (Dry-run) (push) Successful in 50s
Container & Helm chart / Kubernetes Bootstrap Appliance (push) Failing after 6m31s

This commit is contained in:
Danny Bessems 2024-06-11 11:25:35 +10:00
parent 544f98a8fb
commit 594e62cf71
7 changed files with 84 additions and 156 deletions

View File

@ -1,73 +0,0 @@
- block:
- name: Check for existing template on hypervisor
community.vmware.vmware_guest_info:
name: "{{ (filename | basename | split('.'))[:-1] | join('.') }}"
register: existing_ova
ignore_errors: yes
- name: Store inventory path of existing template
ansible.builtin.set_fact:
nodetemplate_inventorypath: "{{ existing_ova.instance.hw_folder ~ '/' ~ existing_ova.instance.hw_name }}"
when: existing_ova is not failed
- block:
- name: Parse OVA file for network mappings
ansible.builtin.shell:
cmd: govc import.spec -json {{ filename }}
environment:
GOVC_INSECURE: '1'
GOVC_URL: "{{ vapp['hv.fqdn'] }}"
GOVC_USERNAME: "{{ vapp['hv.username'] }}"
GOVC_PASSWORD: "{{ vapp['hv.password'] }}"
register: ova_spec
- name: Deploy OVA template on hypervisor
community.vmware.vmware_deploy_ovf:
cluster: "{{ vcenter_info.cluster }}"
datastore: "{{ vcenter_info.datastore }}"
name: "{{ (filename | basename | split('.'))[:-1] | join('.') }}"
networks: "{u'{{ ova_spec.stdout | from_json | json_query('NetworkMapping[0].Name') }}':u'{{ vcenter_info.network }}'}"
allow_duplicates: no
power_on: false
ovf: "{{ filename }}"
register: ova_deploy
- name: Add additional placeholder disk
community.vmware.vmware_guest_disk:
name: "{{ ova_deploy.instance.hw_name }}"
disk:
- size: 1Mb
scsi_controller: 1
scsi_type: paravirtual
unit_number: 0
# Disabled to allow disks to be resized; at the cost of cloning speed
# - name: Create snapshot on deployed VM
# community.vmware.vmware_guest_snapshot:
# name: "{{ ova_deploy.instance.hw_name }}"
# state: present
# snapshot_name: "{{ ansible_date_time.iso8601_basic_short }}-base"
- name: Mark deployed VM as templates
community.vmware.vmware_guest:
name: "{{ ova_deploy.instance.hw_name }}"
is_template: yes
- name: Store inventory path of deployed template
ansible.builtin.set_fact:
nodetemplate_inventorypath: "{{ ova_deploy.instance.hw_folder ~ '/' ~ ova_deploy.instance.hw_name }}"
when: existing_ova is failed
vars:
filename: "{{ query('ansible.builtin.fileglob', '/opt/workloadcluster/node-templates/*.ova') | first }}"
module_defaults:
group/vmware:
hostname: "{{ vapp['hv.fqdn'] }}"
validate_certs: no
username: "{{ vapp['hv.username'] }}"
password: "{{ vapp['hv.password'] }}"
datacenter: "{{ vcenter_info.datacenter }}"
folder: "{{ vcenter_info.folder }}"

View File

@ -0,0 +1,33 @@
- block:
- name: Check for existing template
community.vmware.vmware_guest_info:
name: "{{ vapp['workloadcluster.nodetemplate'] }}"
hostname: "{{ vapp['hv.fqdn'] }}"
validate_certs: false
username: "{{ vapp['hv.username'] }}"
password: "{{ vapp['hv.password'] }}"
datacenter: "{{ vcenter_info.datacenter }}"
folder: "{{ vcenter_info.folder }}"
register: nodetemplate
until:
- nodetemplate is not failed
retries: 600
delay: 30
#wait for 5 hr.
vars:
color_reset: "\e[0m"
ansible_callback_diy_runner_retry_msg: >-
{%- set result = ansible_callback_diy.result.output -%}
{%- set retries_left = result.retries - result.attempts -%}
TEMPLATE '{{ vapp['workloadcluster.nodetemplate'] }}' NOT FOUND; PLEASE UPLOAD MANUALLY -- ({{ retries_left }} retries left)
ansible_callback_diy_runner_retry_msg_color: bright yellow
- name: Store inventory path of existing template
ansible.builtin.set_fact:
nodetemplate_inventorypath: "{{ nodetemplate.instance.hw_folder ~ '/' ~ nodetemplate.instance.hw_name }}"
rescue:
- name: CRITICAL ERROR
ansible.builtin.fail:
msg: Required node-template is not available; cannot continue

View File

@ -1,73 +0,0 @@
- block:
- name: Check for existing template on hypervisor
community.vmware.vmware_guest_info:
name: "{{ (filename | basename | split('.'))[:-1] | join('.') }}"
register: existing_ova
ignore_errors: yes
- name: Store inventory path of existing template
ansible.builtin.set_fact:
nodetemplate_inventorypath: "{{ existing_ova.instance.hw_folder ~ '/' ~ existing_ova.instance.hw_name }}"
when: existing_ova is not failed
- block:
- name: Parse OVA file for network mappings
ansible.builtin.shell:
cmd: govc import.spec -json {{ filename }}
environment:
GOVC_INSECURE: '1'
GOVC_URL: "{{ vapp['hv.fqdn'] }}"
GOVC_USERNAME: "{{ vapp['hv.username'] }}"
GOVC_PASSWORD: "{{ vapp['hv.password'] }}"
register: ova_spec
- name: Deploy OVA template on hypervisor
community.vmware.vmware_deploy_ovf:
cluster: "{{ vcenter_info.cluster }}"
datastore: "{{ vcenter_info.datastore }}"
name: "{{ (filename | basename | split('.'))[:-1] | join('.') }}"
networks: "{u'{{ ova_spec.stdout | from_json | json_query('NetworkMapping[0].Name') }}':u'{{ vcenter_info.network }}'}"
allow_duplicates: no
power_on: false
ovf: "{{ filename }}"
register: ova_deploy
- name: Add additional placeholder disk
community.vmware.vmware_guest_disk:
name: "{{ ova_deploy.instance.hw_name }}"
disk:
- size: 1Gb
scsi_controller: 1
scsi_type: paravirtual
unit_number: 0
# Disabled to allow disks to be resized; at the cost of cloning speed
# - name: Create snapshot on deployed VM
# community.vmware.vmware_guest_snapshot:
# name: "{{ ova_deploy.instance.hw_name }}"
# state: present
# snapshot_name: "{{ ansible_date_time.iso8601_basic_short }}-base"
- name: Mark deployed VM as templates
community.vmware.vmware_guest:
name: "{{ ova_deploy.instance.hw_name }}"
is_template: yes
- name: Store inventory path of deployed template
ansible.builtin.set_fact:
nodetemplate_inventorypath: "{{ ova_deploy.instance.hw_folder ~ '/' ~ ova_deploy.instance.hw_name }}"
when: existing_ova is failed
vars:
filename: "{{ query('ansible.builtin.fileglob', '/opt/metacluster/node-templates/*.ova') | first }}"
module_defaults:
group/vmware:
hostname: "{{ vapp['hv.fqdn'] }}"
validate_certs: no
username: "{{ vapp['hv.username'] }}"
password: "{{ vapp['hv.password'] }}"
datacenter: "{{ vcenter_info.datacenter }}"
folder: "{{ vcenter_info.folder }}"

View File

@ -38,8 +38,29 @@
- name: Configure Ansible defaults - name: Configure Ansible defaults
ansible.builtin.template: ansible.builtin.template:
src: ansible.j2
dest: /etc/ansible/ansible.cfg dest: /etc/ansible/ansible.cfg
content: |
[defaults]
callbacks_enabled = ansible.posix.profile_tasks
force_color = true
stdout_callback = community.general.diy
[callback_diy]
[callback_profile_tasks]
task_output_limit = 0
- name: Create default shell aliases
ansible.builtin.lineinfile:
path: ~/.bashrc
state: present
line: "{{ item }}"
insertafter: EOF
loop:
- alias k="kubectl"
- alias less="less -rf"
loop_control:
label: "{{ (item | regex_findall('([^ =\"]+)'))[2] }}"
- name: Cleanup - name: Cleanup
ansible.builtin.apt: ansible.builtin.apt:

View File

@ -1,6 +0,0 @@
[defaults]
callbacks_enabled = ansible.posix.profile_tasks
force_color = true
[callback_profile_tasks]
task_output_limit = 5

View File

@ -162,6 +162,19 @@ PropertyCategories:
- cp1w1ws1 - cp1w1ws1
UserConfigurable: true UserConfigurable: true
- Key: workloadcluster.nodetemplate
Type: string["ubuntu-2204-kube-v1.30.0", "photon-5-kube-v1.30.0.ova"]
Label: Workload-cluster node template
Description: |
All worker and worker-storage nodes for the workload-cluster will be provisioned with this node template.
Note:
Make sure that this exact template has been uploaded to the vCenter instance before powering on this appliance!
DefaultValue: ubuntu-2204-kube-v1.30.0
Configurations:
- cp1w1ws0
- cp1w1ws1
UserConfigurable: true
- Key: workloadcluster.nodesize - Key: workloadcluster.nodesize
Type: string["small", "medium", "large"] Type: string["small", "medium", "large"]
Label: Workload-cluster node size* Label: Workload-cluster node size*

View File

@ -44,7 +44,7 @@ PropertyCategories:
Configurations: '*' Configurations: '*'
UserConfigurable: true UserConfigurable: true
- Name: 2) Add meta-cluster node - Name: 2) Meta-cluster new node
ProductProperties: ProductProperties:
- Key: guestinfo.hostname - Key: guestinfo.hostname
@ -95,7 +95,20 @@ PropertyCategories:
# Configurations: '*' # Configurations: '*'
# UserConfigurable: true # UserConfigurable: true
- Name: 3) Common - Name: 3) Workload-cluster
ProductProperties:
- Key: workloadcluster.nodetemplate
Type: string["ubuntu-2204-kube-v1.30.0", "photon-5-kube-v1.30.0.ova"]
Label: Workload-cluster node template
Description: |
All worker and worker-storage nodes for the workload-cluster will be provisioned with this node template.
Note:
Make sure that this exact template has been uploaded to the vCenter instance before powering on this appliance!
DefaultValue: ubuntu-2204-kube-v1.30.0
UserConfigurable: true
- Name: 4) Common
ProductProperties: ProductProperties:
- Key: guestinfo.rootsshkey - Key: guestinfo.rootsshkey
@ -106,7 +119,7 @@ PropertyCategories:
Configurations: '*' Configurations: '*'
UserConfigurable: true UserConfigurable: true
- Name: 4) Hypervisor - Name: 5) Hypervisor
ProductProperties: ProductProperties:
- Key: hv.fqdn - Key: hv.fqdn