From 352c98322771af117a85904d580e1c062062d634 Mon Sep 17 00:00:00 2001 From: binary Date: Sat, 7 Nov 2020 20:38:07 +0100 Subject: Refactor vmm role with automation --- roles/vmm/templates/hostname.j2 | 1 + roles/vmm/templates/vm.conf.j2 | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 roles/vmm/templates/hostname.j2 (limited to 'roles/vmm/templates') diff --git a/roles/vmm/templates/hostname.j2 b/roles/vmm/templates/hostname.j2 new file mode 100644 index 0000000..68b989a --- /dev/null +++ b/roles/vmm/templates/hostname.j2 @@ -0,0 +1 @@ +add {{ vmm.switch.interface_host }} diff --git a/roles/vmm/templates/vm.conf.j2 b/roles/vmm/templates/vm.conf.j2 index 88be7fb..2665c16 100644 --- a/roles/vmm/templates/vm.conf.j2 +++ b/roles/vmm/templates/vm.conf.j2 @@ -1,22 +1,22 @@ #jinja2: trim_blocks: True, lstrip_blocks: True -{% for vm in vm.hosts %} -{% set vm = hostvars[vm] %} +{% for vm in vms if hostvars[vm.name] is defined %} +{% set guest = hostvars[vm.name] %} -vm "{{ vm.ansible_host }}" { - {% if vm.enabled %} +vm "{{ guest.ansible_host }}" { + {% if vm.enabled and vm.enabled is defined %} enable {% else %} disable {% endif %} memory {{ vm.memory }} - disk "{{ vmm.disk.dir }}/{{ vm.ansible_host }}.{{ vmm.disk.format }}" + disk "{{ vmm.disk_dir }}/{{ guest.ansible_host }}.{{ vmm.disk_format }}" interface { - switch "{{ vmm.config.switch.name }}" + switch "{{ vmm.switch.name }}" } } {% endfor %} -switch "{{ vmm.config.switch.name }}" { - interface {{ vmm.config.switch.interface }} +switch "{{ vmm.switch.name }}" { + interface {{ vmm.switch.interface }} } -- cgit v1.2.3