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: remove dhcp leases
38 jq 'del( .[] | select(.domain == "{{ jumphost.name }}" or .hostname == "{{ jumphost.name }}"))' /var/lib/libvirt/dnsmasq/virbr0.{{ item }} > /tmp/{{ item }}.tmp
39 mv /tmp/{{ item }}.tmp /var/lib/libvirt/dnsmasq/virbr0.{{ item }}
44 when: deployment_type == 'k8s'
46 - name: clean workspace
48 path: "{{ workspace }}"
51 - name: create workspace if it does not exist
53 path: "{{ workspace }}"
57 - name: create directory for base images
59 path: "{{ images_path }}"
63 - name: download Ubuntu image for jump VM
65 url: https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img
66 dest: "{{ images_path }}/bionic-server-cloudimg-amd64.img"
70 - name: create new VM image from base image
71 command: "qemu-img create -f qcow2 -o backing_file={{ images_path }}/bionic-server-cloudimg-amd64.img {{ workspace }}/{{ jumphost.name }}.qcow2 10G"
73 - name: render config files for jump VM from templates
75 src: "{{ kuberef_root }}/playbooks/roles/jump-vm/templates/{{ item }}.j2"
76 dest: "{{ workspace }}/{{ item }}"
83 - name: create config drive
84 command: "genisoimage -output {{ workspace }}/{{ jumphost.name }}-cidata.iso -volid cidata -joliet -rock \
85 {{ workspace }}/user-data {{ workspace }}/meta-data \
86 {{ workspace + '/network-config' if deployment_type == 'full' else '' }}"
88 # currently commented out because of portability issues between Centos and Ubuntu
89 # - name: setting root password for debugging
91 # command: "virt-customize -a {{ workspace }}/{{ jumphost.name }}.qcow2 --root-password password:'root'"
93 - name: define jump VM
94 command: "virt-install --connect qemu:///system --name {{ jumphost.name }} \
95 --ram 4096 --vcpus=4 --os-type linux --os-variant ubuntu16.04 \
96 --disk path={{ workspace }}/kuberef-jump.qcow2,format=qcow2 \
97 --disk {{ workspace }}/kuberef-jump-cidata.iso,device=cdrom \
98 --network network=default,model=virtio,mac='{{ jumphost.interfaces[engine.net_config[engine.public_network].interface].mac_address }}' \
99 {{ '--network bridge=pxebr,model=rtl8139,mac=' + jumphost.interfaces[engine.net_config[engine.pxe_network].interface].mac_address if deployment_type == 'full' else '' }} \
100 --import --noautoconsole"
102 - name: start jump VM
104 name: "{{ jumphost.name }}"
107 - name: wait for ip to be visible
108 shell: virsh domifaddr "{{ jumphost.name }}" --full | grep "{{ jumphost.interfaces[engine.net_config[engine.public_network].interface].mac_address }}" | awk '{print $4}' | tail -n 1
112 until: ipblock.stdout != ""
113 when: deployment_type == 'k8s'
117 vm_ip: "{{ ipblock.stdout.split('/') }}"
118 when: deployment_type == 'k8s'
120 - name: wait for VM to be reachable
122 host: "{{ ( vm_ip is defined and vm_ip.0 or '' ) if 'k8s' in deployment_type else jumphost.interfaces[idf.net_config[engine.pxe_network].interface].address | default('') }}"