summaryrefslogtreecommitdiff
path: root/roles
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2017-12-11 01:06:27 +0100
committerChristian Pointner <equinox@spreadspace.org>2017-12-11 01:06:27 +0100
commit5796a352aa7b5396decbea1fbc9ef32378a71863 (patch)
tree270a648c5218c00ae0a837eb0323c32bd674d13d /roles
parentinitial config for thetys (diff)
greatly improved vm-install role
Diffstat (limited to 'roles')
-rw-r--r--roles/sshserver/tasks/main.yaml1
-rw-r--r--roles/vm-host/tasks/main.yaml2
-rw-r--r--roles/vm-install/library/wait_for_virt.py59
-rw-r--r--roles/vm-install/tasks/main.yaml11
-rw-r--r--roles/vm-install/templates/libvirt-domain.xml.j22
-rw-r--r--roles/vm-install/templates/preseed_debian-stretch.cfg.j216
-rw-r--r--roles/zsh/tasks/main.yaml2
7 files changed, 54 insertions, 39 deletions
diff --git a/roles/sshserver/tasks/main.yaml b/roles/sshserver/tasks/main.yaml
index fd92f12d..6d6cc59c 100644
--- a/roles/sshserver/tasks/main.yaml
+++ b/roles/sshserver/tasks/main.yaml
@@ -36,4 +36,3 @@
user:
name: root
password: "!"
-
diff --git a/roles/vm-host/tasks/main.yaml b/roles/vm-host/tasks/main.yaml
index 3decb3b2..81262737 100644
--- a/roles/vm-host/tasks/main.yaml
+++ b/roles/vm-host/tasks/main.yaml
@@ -3,6 +3,8 @@
with_items:
- atftpd
- openbsd-inetd
+ - qemu-kvm
+ - libvirt-bin
- python-libvirt
apt:
name: "{{ item }}"
diff --git a/roles/vm-install/library/wait_for_virt.py b/roles/vm-install/library/wait_for_virt.py
index b5e244ef..6c49fae1 100644
--- a/roles/vm-install/library/wait_for_virt.py
+++ b/roles/vm-install/library/wait_for_virt.py
@@ -21,21 +21,23 @@ from ansible.module_utils._text import to_native
VIRT_FAILED = 1
VIRT_SUCCESS = 0
-VIRT_UNAVAILABLE=2
+VIRT_UNAVAILABLE = 2
VIRT_STATE_NAME_MAP = {
- 0 : "running",
- 1 : "running",
- 2 : "running",
- 3 : "paused",
- 4 : "shutdown",
- 5 : "shutdown",
- 6 : "crashed"
+ 0: "running",
+ 1: "running",
+ 2: "running",
+ 3: "paused",
+ 4: "shutdown",
+ 5: "shutdown",
+ 6: "crashed"
}
+
class VMNotFound(Exception):
pass
+
class LibvirtConnection(object):
def __init__(self, uri, module):
@@ -89,7 +91,7 @@ class LibvirtConnection(object):
def get_status(self, vmid):
state = self.find_vm(vmid).info()[0]
- return VIRT_STATE_NAME_MAP.get(state,"unknown")
+ return VIRT_STATE_NAME_MAP.get(state, "unknown")
class Virt(object):
@@ -109,31 +111,32 @@ class Virt(object):
self.__get_conn()
return self.conn.get_status(vmid)
+
def core(module):
- states = module.params.get('states', None)
- guest = module.params.get('name', None)
- uri = module.params.get('uri', None)
- delay = module.params.get('delay', None)
- sleep = module.params.get('sleep', None)
- timeout = module.params.get('timeout', None)
+ states = module.params.get('states', None)
+ guest = module.params.get('name', None)
+ uri = module.params.get('uri', None)
+ delay = module.params.get('delay', None)
+ sleep = module.params.get('sleep', None)
+ timeout = module.params.get('timeout', None)
v = Virt(uri, module)
- res = {'changed': False}
+ res = {'changed': False, 'failed': True}
if delay > 0:
- time.sleep(delay)
+ time.sleep(delay)
for _ in range(0, timeout, sleep):
- state = v.status(guest)
- if state in states:
- res['state'] = state
- res['msg'] = "guest '%s' has reached state: %s" % (guest, state)
- return VIRT_SUCCESS, res
+ state = v.status(guest)
+ if state in states:
+ res['state'] = state
+ res['failed'] = False
+ res['msg'] = "guest '%s' has reached state: %s" % (guest, state)
+ return VIRT_SUCCESS, res
- time.sleep(sleep)
+ time.sleep(sleep)
- res['failed'] = True
res['msg'] = "timeout waiting for guest '%s' to reach one of states: %s" % (guest, ', '.join(states))
return VIRT_FAILED, res
@@ -141,9 +144,9 @@ def core(module):
def main():
module = AnsibleModule(argument_spec=dict(
- name = dict(aliases=['guest'], required=True),
- states = dict(type='list', required=True),
- uri = dict(default='qemu:///system'),
+ name=dict(aliases=['guest'], required=True),
+ states=dict(type='list', required=True),
+ uri=dict(default='qemu:///system'),
delay=dict(type='int', default=0),
sleep=dict(type='int', default=1),
timeout=dict(type='int', default=300),
@@ -166,7 +169,7 @@ def main():
except Exception as e:
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
- if rc != 0: # something went wrong emit the msg
+ if rc != 0: # something went wrong emit the msg
module.fail_json(rc=rc, msg=result)
else:
module.exit_json(**result)
diff --git a/roles/vm-install/tasks/main.yaml b/roles/vm-install/tasks/main.yaml
index 0c95e599..4e5167d2 100644
--- a/roles/vm-install/tasks/main.yaml
+++ b/roles/vm-install/tasks/main.yaml
@@ -73,10 +73,10 @@
wait_for_virt:
name: "{{ inventory_hostname }}"
states: shutdown,crashed
- timeout: 600
+ timeout: 900
delegate_to: "{{ vm_install.host }}"
register: installer_result
- failed_when: installer_result.state == "crashed"
+ failed_when: installer_result.failed or installer_result.state == "crashed"
- name: undefining installer vm
virt:
@@ -113,3 +113,10 @@
wait_for_connection:
delay: 5
timeout: 120
+
+- name: remove dummy logical volume
+ lvol:
+ vg: "{{ inventory_hostname }}"
+ lv: dummy
+ state: absent
+ force: yes
diff --git a/roles/vm-install/templates/libvirt-domain.xml.j2 b/roles/vm-install/templates/libvirt-domain.xml.j2
index c2a4afc5..8fd3b6d7 100644
--- a/roles/vm-install/templates/libvirt-domain.xml.j2
+++ b/roles/vm-install/templates/libvirt-domain.xml.j2
@@ -8,7 +8,7 @@
{% if run_installer %}
<kernel>{{ hostvars[vm_install.host].vm_host.installer.path }}/{{ vmdistro }}-{{ vmdistcodename }}/{{ vm_install.arch | default('amd64') }}/linux</kernel>
<initrd>{{ hostvars[vm_install.host].vm_host.installer.path }}/{{ vmdistro }}-{{ vmdistcodename }}/{{ vm_install.arch | default('amd64') }}/initrd.gz</initrd>
- <cmdline>console=ttyS0,115200n8 auto=true interface=auto url=tftp://{{ hostvars[vm_install.host]['ansible_' + hostvars[vm_install.host].vm_host.installer.net_if].ipv4.address }}/vm-{{ inventory_hostname }}-{{ vmdistro }}-{{ vmdistcodename }}.cfg netcfg/choose_interface=enp1s1 netcfg/disable_autoconfig=true netcfg/get_ipaddress={{ vm_network.internet.ip }} netcfg/get_netmask={{ vm_network.internet.mask }} netcfg/get_gateway={{ vm_network.internet.gateway }} netcfg/get_nameservers={{ vm_network.internet.nameservers }} netcfg/confirm_static=true netcfg/get_hostname={{ inventory_hostname }} netcfg/get_domain={{ vm_network.internet.domain }}</cmdline>
+ <cmdline>console=ttyS0,115200n8 auto=true interface=auto url=tftp://{{ hostvars[vm_install.host]['ansible_' + hostvars[vm_install.host].vm_host.installer.net_if].ipv4.address }}/vm-{{ inventory_hostname }}-{{ vmdistro }}-{{ vmdistcodename }}.cfg netcfg/choose_interface=enp1s1 netcfg/disable_autoconfig=true netcfg/get_ipaddress={{ vm_network.primary.ip }} netcfg/get_netmask={{ vm_network.primary.mask }} netcfg/get_gateway={{ vm_network.primary.gateway }} netcfg/get_nameservers="{{ vm_network.primary.nameservers | join(' ') }}" netcfg/confirm_static=true netcfg/get_hostname={{ inventory_hostname }} netcfg/get_domain={{ vm_network.primary.domain }}</cmdline>
{% endif %}
<boot dev='hd'/>
</os>
diff --git a/roles/vm-install/templates/preseed_debian-stretch.cfg.j2 b/roles/vm-install/templates/preseed_debian-stretch.cfg.j2
index 267da58b..8198d71b 100644
--- a/roles/vm-install/templates/preseed_debian-stretch.cfg.j2
+++ b/roles/vm-install/templates/preseed_debian-stretch.cfg.j2
@@ -10,14 +10,14 @@ d-i keyboard-configuration/xkb-keymap select de
#d-i netcfg/choose_interface select enp1s1
#d-i netcfg/disable_autoconfig boolean false
-#d-i netcfg/get_ipaddress string {{ vm_network.internet.ip }}
-#d-i netcfg/get_netmask string {{ vm_network.internet.mask }}
-#d-i netcfg/get_gateway string {{ vm_network.internet.gateway }}
-#d-i netcfg/get_nameservers string {{ vm_network.internet.nameservers }}
+#d-i netcfg/get_ipaddress string {{ vm_network.primary.ip }}
+#d-i netcfg/get_netmask string {{ vm_network.primary.mask }}
+#d-i netcfg/get_gateway string {{ vm_network.primary.gateway }}
+#d-i netcfg/get_nameservers string {{ vm_network.primary.nameservers | join(' ') }}
#d-i netcfg/confirm_static boolean true
d-i netcfg/get_hostname string {{ inventory_hostname }}
-d-i netcfg/get_domain string {{ vm_network.internet.domain }}
+d-i netcfg/get_domain string {{ vm_network.primary.domain }}
d-i netcfg/wireless_wep string
@@ -70,6 +70,10 @@ d-i partman-auto/expert_recipe string \
mountpoint{ /var/log } \
options/nodev{ nodev } options/noatime{ noatime } \
options/noexec{ noexec } \
+ . \
+ 16 20000 -1 ext4 \
+ $lvmok{ } in_vg{ {{ inventory_hostname }} } \
+ method( keep } lv_name{ dummy } \
.
d-i partman-auto-lvm/no_boot boolean true
@@ -95,4 +99,4 @@ d-i grub-installer/with_other_os boolean false
d-i finish-install/reboot_in_progress note
-d-i preseed/late_command string in-target bash -c "passwd -d root; passwd -l root; umask 077; mkdir -p /root/.ssh/; echo '{{ root_ssh_keys | default('ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCtmysXjBidEwJek6hBgaENiyVOwroFi19xRZZw+cYYqi6asDfF6B/h6gYNkJGWo0rD5ZaLdau1O210O5Xu+TfK1e2bZbxuFIj2fguUkat9wN6IQIO2m2Wcf4k/eiTmtAE3dp0l5ThMqfxxE8dj76mOOrUHCfJUIVoATGs4X5TLcGcXroAcZ+DFFoDzjxjFYNmIuUNtXDwXTpPc63SAYmRvW0ZYZlvH1qZ6irLh+GtE1dZ1Q5lQZvp6xUYcjInbpcd5Ko3KbG/In7sNmUCI7iaTwC4DPDTcHFj99Ll1jruAbdaQqe+ClZv55dbQ+92RDF6fsuQBD8FeRz7nYChvCqNPT1KOvcVsDtbW0iJ1PZ05QdE27w23wJj9OE0JWM09P3AH3ttswHaJ+P4s7mSxxK2m6YZcqop3czLlWWoGna0ynd5eV6l/rtvAQUvBOXjKQ5fPQY5d9cF0Z87NBE54HM9a/IKZ2toU2MuYNUpI/DUoAA9ILS4bJm3AUz8wbaC5EiuIhbM6I/u0NANamaQKRrolGNP4ETaQvhABs+S3/NSSBy4DMjtwax2BxyenF6i89vyHPNY+LZzBOn842yUlEGn6Z11MxiE5fhIfMPUclSYi5bQJDf1fvAyAo59/AX8sPqRK+/OCLIgLwdtW6D4OZGXjqrBJe2j/5uZSJEsl6ROyKw== equinox@spreadspace.org') }}' > /root/.ssh/authorized_keys"
+d-i preseed/late_command string in-target bash -c "passwd -d root; passwd -l root; umask 077; mkdir -p /root/.ssh/; echo -e '{{ sshserver_root_keys }}' > /root/.ssh/authorized_keys"
diff --git a/roles/zsh/tasks/main.yaml b/roles/zsh/tasks/main.yaml
index 409274a9..c1d63b7a 100644
--- a/roles/zsh/tasks/main.yaml
+++ b/roles/zsh/tasks/main.yaml
@@ -20,7 +20,7 @@
shell: /bin/zsh
with_items: "{{ [ 'root' ] | union(zsh_loginshell_user | default([])) }}"
-- name: set zsh the default shell for adduser
+- name: make zsh the default shell for adduser
lineinfile:
regexp: '^#?DSHELL='
line: 'DSHELL=/bin/zsh'