forked from inofix/common-playbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-vm.yml
33 lines (31 loc) · 1.63 KB
/
create-vm.yml
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
#* This playbook creates a vm on a KVM host (via virt-install for now).
#* Currently only debian jessie on amd64 via preseed is supported, extending
#* should not be too difficult, but we had to start somewhere..
#* The playbook is intended to be used by 'maestro', which gets the necessary
#* 'host' dict with the vm info from the knowledge base (reclass-inventory),
#* the 'new__hostname' parameter can be provided as the first argument after
#* the name of the play (See Maestro Examples below).
#* Use '-a' to pass parameters to ansible (as '-e'). See ansible fetch for
#* details.
#* The following arguments are mandatory:
#* - 'new__hostname'
#* - 'host' (dict)
#* Maestro Examples:
#* * Create a VM called <newhost> on <kvmhost>
#* `$ maestro.sh -H <kvmhost> ansible-play create-vm "new__hostname=<newhost>"`
- hosts: host.KVM
vars:
new: '{{ host.resource[new__hostname] }}'
new__system_disk_tmp: '{{ new.disk | selectattr("system") | first() }}'
# TODO why does attr() not work as expected?
new__system_disk:
bus: '{{ host.virt.storage[new__system_disk_tmp.meta.pool].bus }}'
cache: '{{ host.virt.storage[new__system_disk_tmp.meta.pool].cache }}'
name: '{{ new__system_disk_tmp.name }}'
path: '{{ new__system_disk_tmp.path }}'
pool: '{{ new__system_disk_tmp.meta.pool }}'
target: '{{ host.virt.storage[new__system_disk_tmp.meta.pool].path }}/{{ new__hostname }}-{{ new__system_disk_tmp.name }}'
new__system_net: '{{ new.net | selectattr("primary") | first() }}'
os__installer_files: '{{ os__installer_base[new.os.distro][new.os.codename][new.arch] }}'
roles:
- virt-install