1 # Copyright (c) 2017-2018 Intel Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 - name: Remove directory
17 path: "{{ '/tmp/'+node_item.hostname }}"
20 - name: Create directory
22 path: "{{ '/tmp/'+node_item.hostname }}"
26 - name: Define user-data file name
28 user_data: "{{ '/tmp/'+node_item.hostname+'/user-data' }}"
30 - name: Define image-dir
32 image_dir: "{{ '/var/lib/libvirt/images/' }}"
34 - name: Create a new empty file for user-data
36 path: "{{ user_data }}"
41 path: "{{ user_data }}"
45 preserve_hostname: False
46 hostname: {{ node_item.hostname }}
48 all: ">> /var/log/cloud-init.log"
51 - echo 127.0.0.1 {{ node_item.hostname }} >> /etc/hosts
53 - name: {{ node_item.user }}
55 plain_text_passwd: {{ node_item.password }}
56 chpasswd: { expire: False }
57 sudo: ALL=(ALL) NOPASSWD:ALL
60 - name: Remove the marker
62 dest: "{{ user_data }}"
66 - name: Define network-config file name
68 network_config: "{{ '/tmp/'+node_item.hostname+'/network-config' }}"
70 - name: Create a new empty file for network-config
72 path: "{{ network_config }}"
75 - name: Add network-data
77 path: "{{ network_config }}"
83 - name: Define meta-data file name
85 meta_data: "{{ '/tmp/'+node_item.hostname+'/meta-data' }}"
87 - name: Create a new empty file for meta-data
89 path: "{{ meta_data }}"
94 path: "{{ meta_data }}"
97 instance-id: {{ node_item.hostname }}
98 local-hostname: {{ node_item.hostname }}
100 - name: Remove the marker
102 dest: "{{ meta_data }}"
106 - name: Define xml file name
108 xml_file: "{{ '/tmp/'+node_item.hostname+'/'+node_item.hostname+'.xml' }}"
110 - name: Create a new empty file for xml file
112 path: "{{ xml_file }}"
115 - name: Add root "domain" node
117 path: "{{ xml_file }}"
123 - name: Add "type" attribute to "domain" node
125 path: "{{ xml_file }}"
131 - name: Add new children nodes to "domain" node
133 path: "{{ xml_file }}"
136 - name: "{{ node_item.hostname }}"
137 - memory: "{{ node_item.ram }}"
138 - vcpu: "{{ node_item.vcpus }}"
144 - name: Add "unit" attribute to "memory" node
146 path: "{{ xml_file }}"
147 xpath: /domain/memory
152 - name: Add "placement" attribute to "vcpu" node
154 path: "{{ xml_file }}"
160 - name: Add new children nodes to "os" node
162 path: "{{ xml_file }}"
169 - name: Add "arch" attribute to "type" node
171 path: "{{ xml_file }}"
172 xpath: /domain/os/type
177 - name: Add "dev" attribute to "boot" node
179 path: "{{ xml_file }}"
180 xpath: /domain/os/boot
185 - name: Add new children nodes to "cpu" node
187 path: "{{ xml_file }}"
193 - name: Add "mode" attribute to "cpu" node
195 path: "{{ xml_file }}"
198 value: "host-passthrough"
201 - name: Add "mode" attribute to "cache" node
203 path: "{{ xml_file }}"
204 xpath: /domain/cpu/cache
209 - name: Add new children nodes to "devices" node
211 path: "{{ xml_file }}"
212 xpath: /domain/devices
227 - name: Add new children nodes to "disk" node
229 path: "{{ xml_file }}"
230 xpath: /domain/devices/disk
236 file: "{{ '/var/lib/libvirt/images/'+node_item.hostname+'.qcow2' }}"
244 - name: Add new children nodes to "devices" node
246 path: "{{ xml_file }}"
247 xpath: /domain/devices
254 - name: Add new children nodes to "disk" node
256 path: "{{ xml_file }}"
257 xpath: /domain/devices/disk
260 file: "{{ '/var/lib/libvirt/images/'+node_item.hostname+'-ci-data.img' }}"
267 - name: Configure controller
269 path: "{{ xml_file }}"
270 xpath: /domain/devices/controller
276 - name: Configure serial
278 path: "{{ xml_file }}"
279 xpath: /domain/devices/serial
289 - name: Configure console
291 path: "{{ xml_file }}"
292 xpath: /domain/devices/console
306 - name: Populate network-config and add interface to xml file
307 include_tasks: create_interfaces.yml
308 extra_vars: "{{ network_config, xml_file , slot_address, mac_address_counter }}"
310 loop_var: interface_item
311 with_items: "{{ node_item.interfaces }}"
313 - name: Create directory
315 path: "{{ '/tmp/'+node_item.hostname }}"
319 - name: Generate iso image
321 genisoimage -output {{ image_dir+node_item.hostname+'-ci-data.img' }} -volid cidata -joliet
322 -r {{ '/tmp/'+node_item.hostname+'/network-config' }} {{ '/tmp/'+node_item.hostname+'/user-data' }} {{ '/tmp/'+node_item.hostname+'/meta-data' }}
323 &>> {{ '/tmp/'+node_item.hostname+'/hostname.log' }}
325 - name: Copy and convert the ubuntu image
327 qemu-img convert -O qcow2 {{ node_item.image }} {{ image_dir+node_item.hostname+'.qcow2' }}
329 - name: Copy and convert the ubuntu image
331 qemu-img resize {{ image_dir+node_item.hostname+'.qcow2' }} {{ node_item.disk }}MB
333 - name: Define the VMs
336 name: "{{ node_item.hostname }}"
337 xml: "{{ lookup('file', '/tmp/'+node_item.hostname+'/'+node_item.hostname+'.xml') }}"
339 - name: Start the VMs
342 name: "{{ node_item.hostname }}"