airshipctl/playbooks/get-vm-config.yaml
Pallav Gupta 13c4e82f7e AIAP multinode deployment
It deploys 3 controlplane and 2 worker nodes using AIAP gate.

+ kubectl --context target-cluster get node
NAME     STATUS   ROLES                  AGE   VERSION
node01   Ready    control-plane,master   48m   v1.21.2
node03   Ready    worker                 43s   v1.21.2
node04   Ready    control-plane,master   16m   v1.21.2
node05   Ready    control-plane,master   26m   v1.21.2
node06   Ready    worker                 54s   v1.21.2

Tested with 32 GB node.
https://zuul.opendev.org/t/openstack/build/da1c2c440d3d4026ab454de73ee518e2/logs

Closes: #652
Closes: #228

Change-Id: Ie2267e15ed75b57e2e27f45b9be19ddcf7b0a0a8
2022-03-03 14:10:57 +00:00

78 lines
2.8 KiB
YAML

# Licensed under the Apache License, Version 4.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: get BareMetalHost objects
shell: |
set -e
kustomize build --enable-alpha-plugins --network \
{{ airship_config_manifest_directory }}/{{ airship_config_site_path }}/{{ path }} 2>/dev/null |
kustomize cfg grep "kind=BareMetalHost"
register: bmh_command
environment:
KUSTOMIZE_ENABLE_ALPHA_COMMANDS: "true"
SOPS_IMPORT_PGP: "{{ airship_config_pgp }}"
- set_fact:
bmh: "{{ bmh_command.stdout | from_yaml_all | list }}"
- name: get network configuration for BareMetalHost objects
shell: |
set -e
kustomize build --enable-alpha-plugins --network \
{{ airship_config_manifest_directory }}/{{ airship_config_site_path }}/{{ path }} 2>/dev/null |
kustomize cfg grep "metadata.name={{ item.spec.networkData.name }}"
register: netdata_command
failed_when: "netdata_command.stdout == ''"
environment:
KUSTOMIZE_ENABLE_ALPHA_COMMANDS: "true"
SOPS_IMPORT_PGP: "{{ airship_config_pgp }}"
with_items: "{{ bmh }}"
when: bmh|length > 0
- name: get links from network data per BareMetalHost object
set_fact:
links: |
{{
netdata_command.results |
map(attribute='stdout')| map('from_yaml') |
map(attribute='stringData.networkData') | map('from_yaml') |
map(attribute='links') | list
}}
when: bmh|length > 0
- name: define list of VM mac addresses and VM boot mode
set_fact:
vm_cfg: "{{ dict(['boot_mode', 'nat_mac', 'provision_mac'] | zip([item.spec.bootMode, nat_mac_list[0], item.spec.bootMACAddress])) }}"
vars:
nat_mac_list: |
{{
links[idx] |
rejectattr('ethernet_mac_address', 'undefined') |
selectattr('ethernet_mac_address', '!=', item.spec.bootMACAddress) |
map(attribute='ethernet_mac_address') | list
}}
failed_when: nat_mac_list | length == 0
loop: "{{ bmh }}"
loop_control:
index_var: idx
register: vm_cfg_fact
when: bmh|length > 0
- set_fact:
"{{ name }}_vm_cfg": "{{ (lookup('vars', name + '_vm_cfg') |list) + (vm_cfg_fact.results | map(attribute='ansible_facts.vm_cfg') | list) }}"
when: "{{ name + '_vm_cfg' }} is defined and bmh|length > 0"
- set_fact:
"{{ name }}_vm_cfg": "{{ vm_cfg_fact.results | map(attribute='ansible_facts.vm_cfg') | list }}"
when: "{{ name + '_vm_cfg' }} is not defined and bmh|length > 0"