summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2019-07-06 18:17:57 +0200
committerChristian Pointner <equinox@spreadspace.org>2019-07-06 18:17:57 +0200
commitd2fb525388757174343d3229592f917673da8c0b (patch)
treeb924001221a2a4e59cee07c27d2f4ec91cc01f0e
parentadded r3-vex2 (diff)
seperate vm/install and vm/define
-rw-r--r--chaos-at-home/ch-keyserver.yml1
-rw-r--r--roles/debian-installer/defaults/main.yml1
-rw-r--r--roles/vm/define/defaults/main.yml5
-rw-r--r--roles/vm/define/tasks/main.yml49
-rw-r--r--roles/vm/define/templates/libvirt-domain.xml.j2 (renamed from roles/vm/install/templates/libvirt-domain.xml.j2)4
-rw-r--r--roles/vm/install/tasks/main.yml68
6 files changed, 63 insertions, 65 deletions
diff --git a/chaos-at-home/ch-keyserver.yml b/chaos-at-home/ch-keyserver.yml
index 677995ba..78923149 100644
--- a/chaos-at-home/ch-keyserver.yml
+++ b/chaos-at-home/ch-keyserver.yml
@@ -5,3 +5,4 @@
- role: base
- role: sshd
- role: zsh
+ - role: admin-user
diff --git a/roles/debian-installer/defaults/main.yml b/roles/debian-installer/defaults/main.yml
index 448d923e..ba20efdb 100644
--- a/roles/debian-installer/defaults/main.yml
+++ b/roles/debian-installer/defaults/main.yml
@@ -4,7 +4,6 @@ distros:
arch:
- amd64
- i386
-
- distro: debian
codename: buster
arch:
diff --git a/roles/vm/define/defaults/main.yml b/roles/vm/define/defaults/main.yml
new file mode 100644
index 00000000..dbde0d8c
--- /dev/null
+++ b/roles/vm/define/defaults/main.yml
@@ -0,0 +1,5 @@
+---
+vm_define_autostart: "{{ not vm_define_installer and hostvars[hostname].install_cooked.autostart | default(False) }}"
+vm_define_start: yes
+
+vm_define_installer: no
diff --git a/roles/vm/define/tasks/main.yml b/roles/vm/define/tasks/main.yml
new file mode 100644
index 00000000..1dd5017a
--- /dev/null
+++ b/roles/vm/define/tasks/main.yml
@@ -0,0 +1,49 @@
+---
+- name: check if vm already exists
+ virt:
+ name: "{{ hostname }}"
+ command: info
+ register: vmhost_info
+
+- block:
+ - name: destroy exisiting vm
+ virt:
+ name: "{{ hostname }}"
+ state: destroyed
+
+ - name: wait for vm to be destroyed
+ wait_for_virt:
+ name: "{{ hostname }}"
+ states: shutdown,crashed
+ timeout: 5
+
+ - name: undefining exisiting vm
+ virt:
+ name: "{{ hostname }}"
+ command: undefine
+
+ when: hostname in vmhost_info
+
+- name: define vm
+ virt:
+ command: define
+ xml: "{{ lookup('template', 'libvirt-domain.xml.j2') }}"
+
+- when: vm_define_start | bool
+ block:
+ - name: start vm
+ virt:
+ name: "{{ hostname }}"
+ state: running
+
+ - name: wait for VM to start
+ wait_for_virt:
+ name: "{{ hostname }}"
+ states: running
+ timeout: 10
+
+- name: mark vm as autostarted
+ virt:
+ name: "{{ hostname }}"
+ autostart: "{{ vm_define_autostart }}"
+ command: info ## virt module needs either command or state
diff --git a/roles/vm/install/templates/libvirt-domain.xml.j2 b/roles/vm/define/templates/libvirt-domain.xml.j2
index f3bdeae1..60027205 100644
--- a/roles/vm/install/templates/libvirt-domain.xml.j2
+++ b/roles/vm/define/templates/libvirt-domain.xml.j2
@@ -5,7 +5,7 @@
<vcpu>{{ hostvars[hostname].install_cooked.numcpu }}</vcpu>
<os>
<type arch='x86_64' machine='pc-0.12'>hvm</type>
-{% if run_installer %}
+{% if vm_define_installer %}
<kernel>{{ debian_installer_path }}/{{ install_distro }}-{{ install_codename }}/{{ hostvars[hostname].install_cooked.arch | default('amd64') }}/linux</kernel>
<initrd>{{ preseed_tmpdir }}/initrd.preseed.gz</initrd>
<cmdline>console=ttyS0,115200n8</cmdline>
@@ -19,7 +19,7 @@
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
-{% if run_installer %}
+{% if vm_define_installer %}
<on_reboot>destroy</on_reboot>
<on_crash>destroy</on_crash>
{% else %}
diff --git a/roles/vm/install/tasks/main.yml b/roles/vm/install/tasks/main.yml
index 9d603712..a15e2a47 100644
--- a/roles/vm/install/tasks/main.yml
+++ b/roles/vm/install/tasks/main.yml
@@ -8,30 +8,6 @@
lv: "{{ item.value.lv }}"
size: "{{ item.value.size }}"
-- name: check if vm already exists
- virt:
- name: "{{ hostname }}"
- command: info
- register: vmhost_info
-
-- block:
- - name: destroy exisiting vm
- virt:
- name: "{{ hostname }}"
- state: destroyed
-
- - name: wait for vm to be destroyed
- wait_for_virt:
- name: "{{ hostname }}"
- states: shutdown,crashed
- timeout: 5
-
- - name: undefining exisiting vm
- virt:
- name: "{{ hostname }}"
- command: undefine
-
- when: hostname in vmhost_info
- block:
- name: create a temporary workdir
@@ -54,25 +30,12 @@
etype: user
permissions: rx
- - name: define new installer vm
- virt:
- command: define
- xml: "{{ lookup('template', 'libvirt-domain.xml.j2') }}"
+ - import_role:
+ name: vm/define
vars:
- run_installer: yes
+ vm_define_installer: yes
preseed_tmpdir: "{{ tmpdir.path }}"
- - name: start vm
- virt:
- name: "{{ hostname }}"
- state: running
-
- - name: wait for installer to start
- wait_for_virt:
- name: "{{ hostname }}"
- states: running
- timeout: 10
-
- debug:
msg: "you can check on the status of the installer running this command 'virsh console {{ hostname }}' on host {{ inventory_hostname }}."
@@ -84,32 +47,13 @@
register: installer_result
failed_when: installer_result.failed or installer_result.state == "crashed"
- - name: undefining installer vm
- virt:
- name: "{{ hostname }}"
- command: undefine
-
always:
- name: cleanup temporary workdir
file:
path: "{{ tmpdir.path }}"
state: absent
-- name: define new production vm
- virt:
- command: define
- xml: "{{ lookup('template', 'libvirt-domain.xml.j2') }}"
+- import_role:
+ name: vm/define
vars:
- run_installer: no
-
-- name: start vm
- virt:
- name: "{{ hostname }}"
- state: running
-
-- name: mark vm as autostarted
- virt:
- name: "{{ hostname }}"
- autostart: "{{ hostvars[hostname].install_cooked.autostart }}"
- command: info ## virt module needs either command or state
- when: hostvars[hostname].install_cooked.autostart is defined
+ vm_define_installer: no