2 ##############################################################################
3 # Copyright (c) Ericsson AB and others
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 - name: get all running VMs
16 - name: shutdown existing jump VM
18 name: "{{ jumphost.name }}"
21 jumphost.name in running_vms.list_vms
23 - name: get all shutdown VMs
27 register: shutdown_vms
29 - name: undefine existing jump VM
31 name: "{{ jumphost.name }}"
34 jumphost.name in shutdown_vms.list_vms
36 - name: clean workspace
38 path: "{{ workspace }}"
41 - name: create workspace if it does not exist
43 path: "{{ workspace }}"
47 - name: create directory for base images
49 path: "{{ images_path }}"
53 - name: download Ubuntu image for jump VM
55 url: https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img
56 dest: "{{ images_path }}/bionic-server-cloudimg-amd64.img"
60 - name: create new VM image from base image
61 command: "qemu-img create -f qcow2 -o backing_file={{ images_path }}/bionic-server-cloudimg-amd64.img {{ workspace }}/{{ jumphost.name }}.qcow2 10G"
63 - name: render config files for jump VM from templates
65 src: "{{ kuberef_root }}/playbooks/roles/jump-vm/templates/{{ item }}.j2"
66 dest: "{{ workspace }}/{{ item }}"
73 - name: create config drive
74 command: "genisoimage -output {{ workspace }}/{{ jumphost.name }}-cidata.iso -volid cidata -joliet -rock \
75 {{ workspace }}/user-data {{ workspace }}/meta-data {{ workspace }}/network-config"
77 # currently commented out because of portability issues between Centos and Ubuntu
78 # - name: setting root password for debugging
80 # command: "virt-customize -a {{ workspace }}/{{ jumphost.name }}.qcow2 --root-password password:'root'"
82 - name: define jump VM
83 command: "virt-install --connect qemu:///system --name {{ jumphost.name }} \
84 --ram 4096 --vcpus=4 --os-type linux --os-variant ubuntu16.04 \
85 --disk path={{ workspace }}/kuberef-jump.qcow2,format=qcow2 \
86 --disk {{ workspace }}/kuberef-jump-cidata.iso,device=cdrom \
87 --network network=default,model=virtio,mac='{{ jumphost.interfaces[engine.net_config[engine.public_network].interface].mac_address }}' \
88 --network bridge=pxebr,model=rtl8139,mac='{{ jumphost.interfaces[engine.net_config[engine.pxe_network].interface].mac_address }}' \
89 --import --noautoconsole"
93 name: "{{ jumphost.name }}"
96 - name: wait for VM to be reachable
98 host: "{{ jumphost.interfaces[idf.net_config[engine.pxe_network].interface].address }}"