diff --git a/loctevm-reset-iso.inc.yml b/loctevm-provide-iso.inc.yml similarity index 100% rename from loctevm-reset-iso.inc.yml rename to loctevm-provide-iso.inc.yml diff --git a/loctevm-reset-net.inc.yml b/loctevm-provide-net.inc.yml similarity index 100% rename from loctevm-reset-net.inc.yml rename to loctevm-provide-net.inc.yml diff --git a/loctevm-reset-prereq.inc.yml b/loctevm-provide-prereq.inc.yml similarity index 100% rename from loctevm-reset-prereq.inc.yml rename to loctevm-provide-prereq.inc.yml diff --git a/loctevm-reset-vm.inc.yml b/loctevm-provide-vm.inc.yml similarity index 57% rename from loctevm-reset-vm.inc.yml rename to loctevm-provide-vm.inc.yml index 6b8fbd7..ca792b2 100644 --- a/loctevm-reset-vm.inc.yml +++ b/loctevm-provide-vm.inc.yml @@ -12,10 +12,6 @@ dest: "{{ vm_path }}/loctevm.xml" delegate_to: 127.0.0.1 # local action - - name: ensure absence of outdated local known-hosts entry - known_hosts: host={{ansible_host}} state=absent - delegate_to: 127.0.0.1 # local action - - name: define VM virt: command: define @@ -23,11 +19,5 @@ xml: "{{ lookup('file',vm_path ~ '/loctevm.xml') }}" delegate_to: 127.0.0.1 # local action - - name: do dummy connect to ensure new local known host entry - command: ssh -o PasswordAuthentication=no -o StrictHostKeyChecking=no hein@{{ansible_host}} true - delegate_to: 127.0.0.1 # local action - changed_when: False - failed_when: False - when: not inventory_hostname in vms.list_vms # block end diff --git a/loctevm-reset.yml b/loctevm-provide.yml similarity index 59% rename from loctevm-reset.yml rename to loctevm-provide.yml index 26c51e6..aeffb6a 100755 --- a/loctevm-reset.yml +++ b/loctevm-provide.yml @@ -15,6 +15,11 @@ file: path={{ vm_path }} state=directory mode=0755 delegate_to: 127.0.0.1 # local action + - name: remove old image file when asked to reset VM + file: path={{ vm_path }}/loctevm.img state=absent + when: vm_reset|default(False) + delegate_to: 127.0.0.1 # local action + - name: ensure image file # FIXME: change to rm + recreate command: fallocate -l 5G {{ vm_path }}/loctevm.img # 15G? size? args: @@ -26,24 +31,39 @@ delegate_to: 127.0.0.1 # local action - name: get and prepare debian image file - include: loctevm-reset-iso.inc.yml + include: loctevm-provide-iso.inc.yml - name: define Vnd activate Vnet (if not already) - include: loctevm-reset-net.inc.yml + include: loctevm-provide-net.inc.yml - name: define VM (if not already) - include: loctevm-reset-vm.inc.yml + include: loctevm-provide-vm.inc.yml - - name: create VM - should start OS installation + - name: create VM - should start OS installation - might take looong time virt: state: running name: "{{ inventory_hostname }}" + register: virt_run delegate_to: 127.0.0.1 # local action - name: wait for port 80 to appear (after reboot after OS installation) wait_for: host={{ansible_host}} port=80 state=started timeout=2500 delegate_to: 127.0.0.1 # local action + - block: + - name: ensure absence of outdated local known-hosts entry + known_hosts: host={{ansible_host}} state=absent + delegate_to: 127.0.0.1 # local action + + - name: do dummy connect to ensure new local known host entry + command: ssh -o PasswordAuthentication=no -o StrictHostKeyChecking=no hein@{{ansible_host}} true + delegate_to: 127.0.0.1 # local action + changed_when: False + failed_when: False + + when: virt_run.changed + # block end + - hosts: test-vms remote_user: hein gather_facts: False @@ -51,4 +71,4 @@ tasks: - name: prepare VM (if not already) - include: loctevm-reset-prereq.inc.yml + include: loctevm-provide-prereq.inc.yml