Move config to firstboot;Split yaml;Improve feedback
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
eb46c384a8
commit
464ed497fe
@ -0,0 +1,17 @@
|
|||||||
|
- name: Configure clusterctl with hypervisor details
|
||||||
|
ansible.builtin.blockinfile:
|
||||||
|
path: /opt/metacluster/manifests/clusterctl.yml
|
||||||
|
block: |
|
||||||
|
## -- Controller settings -- ##
|
||||||
|
VSPHERE_USERNAME: {{ vapp['hv.username'] }}
|
||||||
|
VSPHERE_PASSWORD: {{ vapp['hv.password'] }}
|
||||||
|
## -- Required workload cluster default settings -- ##
|
||||||
|
VSPHERE_SERVER: "{{ vapp['hv.fqdn'] }}
|
||||||
|
VSPHERE_DATACENTER: {{ vcenter_info.datacenter }}
|
||||||
|
VSPHERE_DATASTORE: {{ vcenter_info.datastore }}
|
||||||
|
VSPHERE_NETWORK: {{ vcenter_info.network }}
|
||||||
|
# VSPHERE_RESOURCE_POOL: ""
|
||||||
|
# VSPHERE_FOLDER: ""
|
||||||
|
# VSPHERE_TEMPLATE: "centos-7-kube-v1.18.2"
|
||||||
|
# VSPHERE_SSH_AUTHORIZED_KEY: "output of cat /root/.ssh/id_rsa.pub"
|
||||||
|
marker: '# {mark} ANSIBLE MANAGED BLOCK'
|
@ -0,0 +1,47 @@
|
|||||||
|
- name: Gather hypervisor details
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: govc ls -L {{ item.moref }} | awk -F/ '{print ${{ item.part }}}'
|
||||||
|
environment:
|
||||||
|
GOVC_INSECURE: '1'
|
||||||
|
GOVC_URL: "{{ vapp['hv.fqdn'] }}"
|
||||||
|
GOVC_USERNAME: "{{ vapp['hv.username'] }}"
|
||||||
|
GOVC_PASSWORD: "{{ vapp['hv.password'] }}"
|
||||||
|
register: govc_inventory
|
||||||
|
loop:
|
||||||
|
- attribute: cluster
|
||||||
|
moref: >-
|
||||||
|
$(govc object.collect -json VirtualMachine:{{ moref_id }} | \
|
||||||
|
jq -r '.[] | select(.Name == "runtime").Val.Host | .Type + ":" + .Value')
|
||||||
|
part: (NF-1)
|
||||||
|
- attribute: datacenter
|
||||||
|
moref: VirtualMachine:{{ moref_id }}
|
||||||
|
part: 2
|
||||||
|
- attribute: datastore
|
||||||
|
moref: >-
|
||||||
|
$(govc object.collect -json VirtualMachine:{{ moref_id }} | \
|
||||||
|
jq -r '.[] | select(.Name == "datastore").Val.ManagedObjectReference | .[].Type + ":" + .[].Value')
|
||||||
|
part: NF
|
||||||
|
- attribute: folder
|
||||||
|
moref: >-
|
||||||
|
$(govc object.collect -json VirtualMachine:{{ moref_id }} | \
|
||||||
|
jq -r '.[] | select(.Name == "parent").Val | .Type + ":" + .Value')
|
||||||
|
part: 0
|
||||||
|
# - attribute: host
|
||||||
|
# moref: >-
|
||||||
|
# $(govc object.collect -json VirtualMachine:{{ moref_id }} | \
|
||||||
|
# jq -r '.[] | select(.Name == "runtime").Val.Host | .Type + ":" + .Value')
|
||||||
|
# part: NF
|
||||||
|
- attribute: network
|
||||||
|
moref: >-
|
||||||
|
$(govc object.collect -json VirtualMachine:{{ moref_id }} | \
|
||||||
|
jq -r '.[] | select(.Name == "network").Val.ManagedObjectReference | .[].Type + ":" + .[].Value')
|
||||||
|
part: NF
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.attribute }}"
|
||||||
|
|
||||||
|
- name: Store hypervisor details in dictionary
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
vcenter_info: "{{ vcenter_info | default({}) | combine({ item.item.attribute : item.stdout }) }}"
|
||||||
|
loop: "{{ govc_inventory.results }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.item.attribute }}"
|
@ -1,106 +1,3 @@
|
|||||||
- block:
|
- import_tasks: hypervisor.yml
|
||||||
|
- import_tasks: clusterapi.yml
|
||||||
- name: Gather hypervisor details
|
- import_tasks: nodetemplates.yml
|
||||||
ansible.builtin.shell:
|
|
||||||
cmd: govc ls -L {{ item.moref }} | awk -F/ '{print ${{ item.part }}}'
|
|
||||||
environment:
|
|
||||||
GOVC_INSECURE: '1'
|
|
||||||
GOVC_URL: "{{ vapp['hv.fqdn'] }}"
|
|
||||||
GOVC_USERNAME: "{{ vapp['hv.username'] }}"
|
|
||||||
GOVC_PASSWORD: "{{ vapp['hv.password'] }}"
|
|
||||||
register: govc_inventory
|
|
||||||
loop:
|
|
||||||
- attribute: cluster
|
|
||||||
moref: >-
|
|
||||||
$(govc object.collect -json VirtualMachine:{{ moref_id }} | \
|
|
||||||
jq -r '.[] | select(.Name == "runtime").Val.Host | .Type + ":" + .Value')
|
|
||||||
part: (NF-1)
|
|
||||||
- attribute: datacenter
|
|
||||||
moref: VirtualMachine:{{ moref_id }}
|
|
||||||
part: 2
|
|
||||||
- attribute: datastore
|
|
||||||
moref: >-
|
|
||||||
$(govc object.collect -json VirtualMachine:{{ moref_id }} | \
|
|
||||||
jq -r '.[] | select(.Name == "datastore").Val.ManagedObjectReference | .[].Type + ":" + .[].Value')
|
|
||||||
part: NF
|
|
||||||
- attribute: folder
|
|
||||||
moref: >-
|
|
||||||
$(govc object.collect -json VirtualMachine:{{ moref_id }} | \
|
|
||||||
jq -r '.[] | select(.Name == "parent").Val | .Type + ":" + .Value')
|
|
||||||
part: 0
|
|
||||||
# - attribute: host
|
|
||||||
# moref: >-
|
|
||||||
# $(govc object.collect -json VirtualMachine:{{ moref_id }} | \
|
|
||||||
# jq -r '.[] | select(.Name == "runtime").Val.Host | .Type + ":" + .Value')
|
|
||||||
# part: NF
|
|
||||||
- attribute: network
|
|
||||||
moref: >-
|
|
||||||
$(govc object.collect -json VirtualMachine:{{ moref_id }} | \
|
|
||||||
jq -r '.[] | select(.Name == "network").Val.ManagedObjectReference | .[].Type + ":" + .[].Value')
|
|
||||||
part: NF
|
|
||||||
loop_control:
|
|
||||||
label: "{{ item.attribute }}"
|
|
||||||
|
|
||||||
- name: Store hypervisor details in dictionary
|
|
||||||
ansible.builtin.set_fact:
|
|
||||||
vcenter_info: "{{ vcenter_info | default({}) | combine({ item.item.attribute : item.stdout }) }}"
|
|
||||||
loop: "{{ govc_inventory.results }}"
|
|
||||||
loop_control:
|
|
||||||
label: "{{ item.item.attribute }}"
|
|
||||||
|
|
||||||
- block:
|
|
||||||
|
|
||||||
- name: Check for existing templates on hypervisor
|
|
||||||
community.vmware.vmware_guest_info:
|
|
||||||
name: "{{ (item | basename | split('.'))[:-1] | join('.') }}"
|
|
||||||
register: existing_ova
|
|
||||||
loop: "{{ query('ansible.builtin.fileglob', '/opt/workloadcluster/node-templates/*.ova') | sort }}"
|
|
||||||
ignore_errors: yes
|
|
||||||
|
|
||||||
- name: Parse OVA files for network mappings
|
|
||||||
ansible.builtin.shell:
|
|
||||||
cmd: govc import.spec -json {{ item }}
|
|
||||||
environment:
|
|
||||||
GOVC_INSECURE: '1'
|
|
||||||
GOVC_URL: "{{ vapp['hv.fqdn'] }}"
|
|
||||||
GOVC_USERNAME: "{{ vapp['hv.username'] }}"
|
|
||||||
GOVC_PASSWORD: "{{ vapp['hv.password'] }}"
|
|
||||||
register: ova_spec
|
|
||||||
when: existing_ova.results[index] is failed
|
|
||||||
loop: "{{ query('ansible.builtin.fileglob', '/opt/workloadcluster/node-templates/*.ova') | sort }}"
|
|
||||||
loop_control:
|
|
||||||
index_var: index
|
|
||||||
|
|
||||||
- name: Deploy OVA templates on hypervisor
|
|
||||||
community.vmware.vmware_deploy_ovf:
|
|
||||||
cluster: "{{ vcenter_info.cluster }}"
|
|
||||||
datastore: "{{ vcenter_info.datastore }}"
|
|
||||||
folder: "{{ vcenter_info.folder }}"
|
|
||||||
name: "{{ (item | basename | split('.'))[:-1] | join('.') }}"
|
|
||||||
networks: "{u'{{ ova_spec.results[index].stdout | from_json | json_query('NetworkMapping[0].Name') }}':u'{{ vcenter_info.network }}'}"
|
|
||||||
allow_duplicates: no
|
|
||||||
power_on: false
|
|
||||||
ovf: "{{ item }}"
|
|
||||||
register: ova_deploy
|
|
||||||
when: existing_ova.results[index] is failed
|
|
||||||
loop: "{{ query('ansible.builtin.fileglob', '/opt/workloadcluster/node-templates/*.ova') | sort }}"
|
|
||||||
loop_control:
|
|
||||||
index_var: index
|
|
||||||
|
|
||||||
- name: Mark deployed VM's as templates
|
|
||||||
community.vmware.vmware_guest:
|
|
||||||
name: "{{ item.instance.hw_name }}"
|
|
||||||
is_template: yes
|
|
||||||
when: ova_deploy.results[index] is not skipped
|
|
||||||
loop: "{{ ova_deploy.results }}"
|
|
||||||
loop_control:
|
|
||||||
index_var: index
|
|
||||||
label: "{{ item.item }}"
|
|
||||||
|
|
||||||
module_defaults:
|
|
||||||
group/vmware:
|
|
||||||
hostname: "{{ vapp['hv.fqdn'] }}"
|
|
||||||
validate_certs: no
|
|
||||||
username: "{{ vapp['hv.username'] }}"
|
|
||||||
password: "{{ vapp['hv.password'] }}"
|
|
||||||
datacenter: "{{ vcenter_info.datacenter }}"
|
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
- block:
|
||||||
|
|
||||||
|
- name: Check for existing templates on hypervisor
|
||||||
|
community.vmware.vmware_guest_info:
|
||||||
|
name: "{{ (item | basename | split('.'))[:-1] | join('.') }}"
|
||||||
|
register: existing_ova
|
||||||
|
loop: "{{ query('ansible.builtin.fileglob', '/opt/workloadcluster/node-templates/*.ova') | sort }}"
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: Parse OVA files for network mappings
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: govc import.spec -json {{ item }}
|
||||||
|
environment:
|
||||||
|
GOVC_INSECURE: '1'
|
||||||
|
GOVC_URL: "{{ vapp['hv.fqdn'] }}"
|
||||||
|
GOVC_USERNAME: "{{ vapp['hv.username'] }}"
|
||||||
|
GOVC_PASSWORD: "{{ vapp['hv.password'] }}"
|
||||||
|
register: ova_spec
|
||||||
|
when: existing_ova.results[index] is failed
|
||||||
|
loop: "{{ query('ansible.builtin.fileglob', '/opt/workloadcluster/node-templates/*.ova') | sort }}"
|
||||||
|
loop_control:
|
||||||
|
index_var: index
|
||||||
|
|
||||||
|
- name: Deploy OVA templates on hypervisor
|
||||||
|
community.vmware.vmware_deploy_ovf:
|
||||||
|
cluster: "{{ vcenter_info.cluster }}"
|
||||||
|
datastore: "{{ vcenter_info.datastore }}"
|
||||||
|
folder: "{{ vcenter_info.folder }}"
|
||||||
|
name: "{{ (item | basename | split('.'))[:-1] | join('.') }}"
|
||||||
|
networks: "{u'{{ ova_spec.results[index].stdout | from_json | json_query('NetworkMapping[0].Name') }}':u'{{ vcenter_info.network }}'}"
|
||||||
|
allow_duplicates: no
|
||||||
|
power_on: false
|
||||||
|
ovf: "{{ item }}"
|
||||||
|
register: ova_deploy
|
||||||
|
when: existing_ova.results[index] is failed
|
||||||
|
loop: "{{ query('ansible.builtin.fileglob', '/opt/workloadcluster/node-templates/*.ova') | sort }}"
|
||||||
|
loop_control:
|
||||||
|
index_var: index
|
||||||
|
|
||||||
|
- name: Mark deployed VM's as templates
|
||||||
|
community.vmware.vmware_guest:
|
||||||
|
name: "{{ item.instance.hw_name }}"
|
||||||
|
is_template: yes
|
||||||
|
when: ova_deploy.results[index] is not skipped
|
||||||
|
loop: "{{ ova_deploy.results }}"
|
||||||
|
loop_control:
|
||||||
|
index_var: index
|
||||||
|
label: "{{ item.item }}"
|
||||||
|
|
||||||
|
module_defaults:
|
||||||
|
group/vmware:
|
||||||
|
hostname: "{{ vapp['hv.fqdn'] }}"
|
||||||
|
validate_certs: no
|
||||||
|
username: "{{ vapp['hv.username'] }}"
|
||||||
|
password: "{{ vapp['hv.password'] }}"
|
||||||
|
datacenter: "{{ vcenter_info.datacenter }}"
|
@ -89,10 +89,6 @@
|
|||||||
dest: /opt/metacluster/manifests/clusterctl.yaml
|
dest: /opt/metacluster/manifests/clusterctl.yaml
|
||||||
vars:
|
vars:
|
||||||
_template:
|
_template:
|
||||||
hv:
|
|
||||||
fqdn: "{{ vapp['hv.fqdn'] }}"
|
|
||||||
username: "{{ vapp['hv.username'] }}"
|
|
||||||
password: "{{ vapp['hv.password'] }}"
|
|
||||||
version:
|
version:
|
||||||
base: "{{ components.clusterapi.manifest.version.base }}"
|
base: "{{ components.clusterapi.manifest.version.base }}"
|
||||||
infrastructure_vsphere: "{{ components.clusterapi.manifest.version.infrastructure_vsphere }}"
|
infrastructure_vsphere: "{{ components.clusterapi.manifest.version.infrastructure_vsphere }}"
|
||||||
|
@ -11,16 +11,3 @@ providers:
|
|||||||
- name: "vsphere"
|
- name: "vsphere"
|
||||||
url: "/opt/metacluster/manifests/infrastructure-vsphere/{{ _template.version.infrastructure-vsphere }}/infrastructure-components.yaml"
|
url: "/opt/metacluster/manifests/infrastructure-vsphere/{{ _template.version.infrastructure-vsphere }}/infrastructure-components.yaml"
|
||||||
type: "InfrastructureProvider"
|
type: "InfrastructureProvider"
|
||||||
|
|
||||||
## -- Controller settings -- ##
|
|
||||||
VSPHERE_USERNAME: "{{ _template.hv.username }}"
|
|
||||||
VSPHERE_PASSWORD: "{{ _template.hv.password }}"
|
|
||||||
## -- Required workload cluster default settings -- ##
|
|
||||||
VSPHERE_SERVER: "{{ _template.hv.fqdn }}"
|
|
||||||
VSPHERE_DATACENTER: "{{ _template.hv.datacenter }}"
|
|
||||||
VSPHERE_DATASTORE: "{{ _template.hv.datastore }}"
|
|
||||||
VSPHERE_NETWORK: "{{ _template.hv.network }}"
|
|
||||||
#VSPHERE_RESOURCE_POOL: ""
|
|
||||||
#VSPHERE_FOLDER: ""
|
|
||||||
#VSPHERE_TEMPLATE: "centos-7-kube-v1.18.2"
|
|
||||||
#VSPHERE_SSH_AUTHORIZED_KEY: "output of cat /root/.ssh/id_rsa.pub"
|
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
line: 'NAutoVTs=1'
|
line: 'NAutoVTs=1'
|
||||||
- regexp: '^#ReserveVT='
|
- regexp: '^#ReserveVT='
|
||||||
line: 'ReserveVT=11'
|
line: 'ReserveVT=11'
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.line }}"
|
||||||
|
|
||||||
- name: Mask getty@tty1 service
|
- name: Mask getty@tty1 service
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
|
Loading…
Reference in New Issue
Block a user