96 lines
3.1 KiB
YAML
96 lines
3.1 KiB
YAML
---
|
|
- name: Wubwub
|
|
debug:
|
|
msg: Well, let's get crackin'
|
|
|
|
- name: Check if image exists
|
|
stat:
|
|
path: "{{ vm.image }}"
|
|
register: xen_vm_creator_image_path_check
|
|
failed_when: not xen_vm_creator_image_path_check.stat.exists
|
|
|
|
# create boot iso
|
|
- name: Create config drive
|
|
shell: |
|
|
genconfdrv -H {{ vm.hostname }} -o {{ xen_vm_creator_iso_dir }}/{{ vm.hostname}}.iso --ndsc \
|
|
{% if user_list %}-a {% for user in user_list %}{{ user | quote }} {% endfor %}{% endif %}\
|
|
{% if net_list %}-i {% for net in net_list %}{{ net | quote }} {% endfor %}{% endif %}
|
|
vars:
|
|
user_def: "{{ vm.user | default(xen_vm_creator_default_user) }}"
|
|
user_list: "[{% for user in user_def %}'{{ user.name }}:{{ user.key }}',{% endfor %}]"
|
|
net_list: |
|
|
[
|
|
{% for net in vm.networks %}
|
|
{% set iface = net.interface|default(xen_vm_creator_interface_prefix + loop.index0|string) %}
|
|
'{{ iface }}'
|
|
{% if net.address|default %}
|
|
':{{ net.address }}'
|
|
{% if net.gateway|default %}
|
|
':{{ net.gateway }}'
|
|
{% endif %}
|
|
{% if net.routes|default %}
|
|
{% if not net.gateway|default %}
|
|
':'
|
|
{% endif %}
|
|
{% for route in net.routes %}
|
|
':{{ route.route }}-{{ route.gw }}'
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endif %}
|
|
,
|
|
|
|
{% if net.address6|default %}
|
|
'{{ iface }};{{ net.address6 }}'
|
|
{% if net.gateway6|default %}
|
|
';{{ net.gateway6 }}'
|
|
{% endif %}
|
|
{% if net.routes6|default %}
|
|
{% if not net.gateway6|default %}
|
|
';'
|
|
{% endif %}
|
|
{% for route in net.routes6 %}
|
|
';{{ route.net }}-{{ route.gw }}'
|
|
{% endfor %}
|
|
{% endif %}
|
|
,
|
|
{% endif %}
|
|
{% endfor %}
|
|
]
|
|
|
|
# push config
|
|
- name: Write VM config
|
|
template:
|
|
src: xen-vm.cfg.j2
|
|
dest: "{{ xen_vm_creator_xen_config_dir }}/{{ vm.hostname }}.cfg"
|
|
vars:
|
|
iso_path: "{{ xen_vm_creator_iso_dir }}/{{ vm.hostname}}.iso"
|
|
storage_path: "phy:/dev/{{ xen_vm_creator_lvm_vg_name }}/{{ vm.hostname }}-disk"
|
|
extra_storage_args: "{{ xen_vm_creator_extra_storage_args|default }}"
|
|
|
|
# provision storage
|
|
# --> lvm: create lv (lvol size/vg/lv)
|
|
- name: Create LVM volume
|
|
lvol:
|
|
lv: "{{ vm.hostname }}-disk"
|
|
vg: "{{ xen_vm_creator_lvm_vg_name }}"
|
|
size: "{{ vm.disk_size }}g"
|
|
|
|
# qemu-img for image
|
|
- name: Write image
|
|
shell: "qemu-img convert -O raw {{ vm.image|quote }} /dev/{{ xen_vm_creator_lvm_vg_name }}/{{ vm.hostname }}-disk"
|
|
|
|
# start vm
|
|
- name: Start VM
|
|
shell: "xl create {{ xen_vm_creator_xen_config_dir }}/{{ vm.hostname }}.cfg"
|
|
|
|
- name: Wait 10 seconds for VM to be started
|
|
wait_for:
|
|
timeout: 10
|
|
|
|
# remove iso from config
|
|
- name: Remove config drive from VM config
|
|
lineinfile:
|
|
path: "{{ xen_vm_creator_xen_config_dir }}/{{ vm.hostname }}.cfg"
|
|
state: absent
|
|
regexp: "^.*{{ xen_vm_creator_iso_file_marker }}$"
|