-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnet_and_vm.yaml
55 lines (47 loc) · 1.51 KB
/
net_and_vm.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
- name: Create net and vm
hosts: localhost
become: true
become_method: sudo
vars:
interface: eno1
br_name: br0
ip: 192.168.8.108/24
gw: 192.168.8.1
br_ip: 192.168.8.130
ip_start: 192.168.8.131
ip_end: 192.168.8.141
tasks:
- name: Creating network
template:
src: /home/pc-5/ansible/templates/template-network.j2
dest: /etc/netplan/00-installer-config.yaml
- name: Creating xml
template:
src: /home/pc-5/ansible/templates/template_xml.j2
dest: /home/pc-5/ansible/xml/host-bridge.xml
command: ~/ansible/scripts/net.sh
- name: Create VMs
hosts: localhost
become: true
vars_files:
- vms.yaml
tasks:
- name: Get list of VMs
virt:
command: "list_vms"
register: vms
- name: Create VM
command: >
virt-install --import --virt-type=kvm --name {{ item.key }}
--memory {{ item.value.mem }} --vcpus {{ item.value.cpus }}
--os-variant {{ item.value.os_type }} --hvm
--cdrom={{ item.value.cdrom_path }} --network network={{ item.value.network }}
--graphics vnc --disk path={{ item.value.disk_path }},size={{ item.value.disk_size }}
when: item.key not in vms.list_vms
with_dict: "{{ guests }}"
- name: Start VM
virt:
name: "{{ item.key }}"
state: running
with_dict: "{{ guests }}"