A CLI for managing declarative infrastructure.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
airshipctl/tools/airship-in-a-pod/infra-builder/assets/opt/ansible/playbooks/roles/build-infra/tasks/create-vm.yaml

59 lines
2.1 KiB

# Licensed under the Apache License, Version 2.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.
- set_fact:
qcow_rand: "{{ 6000 | random }}"
- name: "Create qemu image extra block devices"
shell: |
qemu-img create \
-f qcow2 \
"{{ floorplan.image_pool }}/{{ vm_instance.name }}-{{ seq }}-{{ qcow_rand }}".qcow2 "{{ vm_instance.block[(seq | int)-1] }}"
with_sequence:
start=1 end="{{ (vm_instance.block | length | int ) }}"
loop_control:
loop_var: seq
- acl:
default: true
path: "{{ floorplan.image_pool }}"
entry: "u:libvirt-qemu:r-x"
state: present
- name: Define vm xml
shell: |
virt-install \
--connect "{{ floorplan.uri }}" \
--os-variant "{{ floorplan.os_variant }}" \
--machine pc \
--name "{{ vm_name }}" \
--memory "{{ vm_instance.ram }}" \
--network network="air_nat",address.type='pci',address.domain=0,address.bus=0,address.slot=3,address.function=0,mac="{{ vm_instance.nat_mac_address[vm_index | int] }}" \
--network network="air_prov",address.type='pci',address.domain=0,address.bus=0,address.slot=4,address.function=0,mac="{{ vm_instance.prov_mac_address[vm_index | int] }}" \
--cpu host-passthrough \
--vcpus "{{ vm_instance.cpu | int }}" \
--import \
{% for i in range(1, (vm_instance.block | length | int )+1) %}
--disk "{{ floorplan.image_pool }}/{{ vm_instance.name }}-{{ i }}-{{ qcow_rand }}.qcow2,bus=scsi,format=qcow2" \
{% endfor %}
--nographics \
--noautoconsole \
--print-xml
register: vm_xml
- debug:
msg: "{{ vm_xml }}"
- name: Create vm
virt:
command: define
xml: "{{ vm_xml.stdout }}"