This includes renaming vm_install_host to vm_host.
---
localconfig_ssh_config_user: root
-vm_install_host: alfred
+vm_host: alfred
-vm_install:
- host: "{{ vm_install_host }}"
+install:
+ host: "{{ vm_host }}"
mem: 1024
numcpu: 2
disks:
lv: "{{ inventory_hostname }}"
size: 10g
interfaces:
- - bridge: "{{ hostvars[vm_install_host].vm_host.network.interface }}"
+ - bridge: "{{ hostvars[vm_host].vm_host.network.interface }}"
name: mgmt0
- bridge: "br-svc"
name: svc0
autostart: True
-vm_network:
- nameservers: "{{ hostvars[vm_install_host].vm_host.network.nameservers }}"
+network:
+ nameservers: "{{ hostvars[vm_host].vm_host.network.nameservers }}"
domain: realraum.at
systemd_link:
- interfaces: "{{ vm_install.interfaces }}"
+ interfaces: "{{ install.interfaces }}"
primary:
interface: mgmt0
- ip: "{{ (hostvars[vm_install_host].vm_host.network.ip+'/'+hostvars[vm_install_host].vm_host.network.mask) | ipaddr(hostvars[vm_install_host].vm_host.network.indices[inventory_hostname]) | ipaddr('address') }}"
- mask: "{{ hostvars[vm_install_host].vm_host.network.mask }}"
- gateway: "{{ hostvars[vm_install_host].vm_host.network.gateway | default(hostvars[vm_install_host].vm_host.network.ip) }}"
+ ip: "{{ (hostvars[vm_host].vm_host.network.ip+'/'+hostvars[vm_host].vm_host.network.mask) | ipaddr(hostvars[vm_host].vm_host.network.indices[inventory_hostname]) | ipaddr('address') }}"
+ mask: "{{ hostvars[vm_host].vm_host.network.mask }}"
+ gateway: "{{ hostvars[vm_host].vm_host.network.gateway | default(hostvars[vm_host].vm_host.network.ip) }}"
- r3-{{ hostname }}
- r3g-{{ hostname }}
- r3e-{{ hostname }}
- - "{{ hostvars[hostname].vm_network_cooked.primary.ip }}"
+ - "{{ hostvars[hostname].network_cooked.primary.ip }}"
d-i netcfg/disable_dhcp boolean true
d-i netcfg/choose_interface select enp1s1
d-i netcfg/disable_autoconfig boolean false
-d-i netcfg/get_ipaddress string {{ hostvars[hostname].vm_network_cooked.primary.ip }}
-d-i netcfg/get_netmask string {{ hostvars[hostname].vm_network_cooked.primary.mask }}
-d-i netcfg/get_gateway string {{ hostvars[hostname].vm_network_cooked.primary.gateway }}
-d-i netcfg/get_nameservers string {{ hostvars[hostname].vm_network_cooked.nameservers | join(' ') }}
+d-i netcfg/get_ipaddress string {{ hostvars[hostname].network_cooked.primary.ip }}
+d-i netcfg/get_netmask string {{ hostvars[hostname].network_cooked.primary.mask }}
+d-i netcfg/get_gateway string {{ hostvars[hostname].network_cooked.primary.gateway }}
+d-i netcfg/get_nameservers string {{ hostvars[hostname].network_cooked.nameservers | join(' ') }}
d-i netcfg/confirm_static boolean true
d-i netcfg/get_hostname string {{ hostname }}
-d-i netcfg/get_domain string {{ hostvars[hostname].vm_network_cooked.domain }}
+d-i netcfg/get_domain string {{ hostvars[hostname].network_cooked.domain }}
d-i netcfg/wireless_wep string
d-i clock-setup/ntp boolean false
-d-i partman-auto/disk string /dev/{{ hostvars[hostname].vm_install_cooked.disks.primary }}
+d-i partman-auto/disk string /dev/{{ hostvars[hostname].install_cooked.disks.primary }}
d-i partman-auto/method string lvm
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i pkgsel/upgrade select safe-upgrade
popularity-contest popularity-contest/participate boolean false
-d-i grub-installer/choose_bootdev string /dev/{{ hostvars[hostname].vm_install_cooked.disks.primary }}
+d-i grub-installer/choose_bootdev string /dev/{{ hostvars[hostname].install_cooked.disks.primary }}
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean false
#d-i netcfg/choose_interface select enp1s1
#d-i netcfg/disable_autoconfig boolean false
-#d-i netcfg/get_ipaddress string {{ hostvars[hostname].vm_network_cooked.primary.ip }}
-#d-i netcfg/get_netmask string {{ hostvars[hostname].vm_network_cooked.primary.mask }}
-#d-i netcfg/get_gateway string {{ hostvars[hostname].vm_network_cooked.primary.gateway }}
-#d-i netcfg/get_nameservers string {{ hostvars[hostname].vm_network_cooked.nameservers | join(' ') }}
+#d-i netcfg/get_ipaddress string {{ hostvars[hostname].network_cooked.primary.ip }}
+#d-i netcfg/get_netmask string {{ hostvars[hostname].network_cooked.primary.mask }}
+#d-i netcfg/get_gateway string {{ hostvars[hostname].network_cooked.primary.gateway }}
+#d-i netcfg/get_nameservers string {{ hostvars[hostname].network_cooked.nameservers | join(' ') }}
#d-i netcfg/confirm_static boolean true
d-i netcfg/get_hostname string {{ hostname }}
-d-i netcfg/get_domain string {{ hostvars[hostname].vm_network_cooked.domain }}
+d-i netcfg/get_domain string {{ hostvars[hostname].network_cooked.domain }}
d-i netcfg/wireless_wep string
d-i clock-setup/ntp boolean false
-d-i partman-auto/disk string /dev/{{ hostvars[hostname].vm_install_cooked.disks.primary }}
+d-i partman-auto/disk string /dev/{{ hostvars[hostname].install_cooked.disks.primary }}
d-i partman-auto/method string lvm
d-i partman-auto/purge_lvm_from_device boolean true
d-i partman-auto-lvm/new_vg_name string {{ hostname }}
popularity-contest popularity-contest/participate boolean false
d-i pkgsel/update-policy select none
-d-i grub-installer/choose_bootdev string /dev/{{ hostvars[hostname].vm_install_cooked.disks.primary }}
+d-i grub-installer/choose_bootdev string /dev/{{ hostvars[hostname].install_cooked.disks.primary }}
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean false
content: |
[Service]
ExecStart=
- ExecStart=-/sbin/agetty --keep-baud 115200,38400,9600 --noclear --autologin root --login-pause --host {{ vm_install_host }} %I $TERM
+ ExecStart=-/sbin/agetty --keep-baud 115200,38400,9600 --noclear --autologin root --login-pause --host {{ vm_host }} %I $TERM
---
- name: create disks for vm
- with_dict: "{{ hostvars[hostname].vm_install_cooked.disks.virtio | default({}) | combine(hostvars[hostname].vm_install_cooked.disks.scsi | default({})) }}"
+ with_dict: "{{ hostvars[hostname].install_cooked.disks.virtio | default({}) | combine(hostvars[hostname].install_cooked.disks.scsi | default({})) }}"
lvol:
vg: "{{ item.value.vg }}"
lv: "{{ item.value.lv }}"
- name: mark vm as autostarted
virt:
name: "{{ hostname }}"
- autostart: "{{ hostvars[hostname].vm_install_cooked.autostart }}"
+ autostart: "{{ hostvars[hostname].install_cooked.autostart }}"
command: info ## virt module needs either command or state
- when: hostvars[hostname].vm_install_cooked.autostart is defined
+ when: hostvars[hostname].install_cooked.autostart is defined
<domain type='kvm'>
<name>{{ hostname }}</name>
- <memory>{{ hostvars[hostname].vm_install_cooked.mem * 1024 }}</memory>
- <currentMemory>{{ hostvars[hostname].vm_install_cooked.mem * 1024 }}</currentMemory>
- <vcpu>{{ hostvars[hostname].vm_install_cooked.numcpu }}</vcpu>
+ <memory>{{ hostvars[hostname].install_cooked.mem * 1024 }}</memory>
+ <currentMemory>{{ hostvars[hostname].install_cooked.mem * 1024 }}</currentMemory>
+ <vcpu>{{ hostvars[hostname].install_cooked.numcpu }}</vcpu>
<os>
<type arch='x86_64' machine='pc-0.12'>hvm</type>
{% if run_installer %}
- <kernel>{{ debian_installer_path }}/{{ distro }}-{{ distcodename }}/{{ hostvars[hostname].vm_install_cooked.arch | default('amd64') }}/linux</kernel>
+ <kernel>{{ debian_installer_path }}/{{ distro }}-{{ distcodename }}/{{ hostvars[hostname].install_cooked.arch | default('amd64') }}/linux</kernel>
<initrd>{{ preseed_path }}/{{ hostname }}-{{ distro }}-{{ distcodename }}.initrd.gz</initrd>
<cmdline>console=ttyS0,115200n8</cmdline>
{% endif %}
<backend model='random'>/dev/urandom</backend>
</rng>
-{% if 'virtio' in hostvars[hostname].vm_install_cooked.disks %}
-{% for device, lv in hostvars[hostname].vm_install_cooked.disks.virtio.items() %}
+{% if 'virtio' in hostvars[hostname].install_cooked.disks %}
+{% for device, lv in hostvars[hostname].install_cooked.disks.virtio.items() %}
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' discard='unmap'/>
<source dev='/dev/mapper/{{ lv.vg | replace('-', '--') }}-{{ lv.lv | replace('-', '--') }}'/>
{% endfor %}
{% endif %}
-{% if 'scsi' in hostvars[hostname].vm_install_cooked.disks %}
+{% if 'scsi' in hostvars[hostname].install_cooked.disks %}
<controller type='scsi' index='0' model='virtio-scsi'/>
-{% for device, lv in hostvars[hostname].vm_install_cooked.disks.scsi.items() %}
+{% for device, lv in hostvars[hostname].install_cooked.disks.scsi.items() %}
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' discard='unmap'/>
<source dev='/dev/mapper/{{ lv.vg | replace('-', '--') }}-{{ lv.lv | replace('-', '--') }}'/>
{% endfor %}
{% endif %}
-{% if hostvars[hostname].vm_install_cooked.interfaces %}
-{% for if in hostvars[hostname].vm_install_cooked.interfaces %}
+{% if hostvars[hostname].install_cooked.interfaces %}
+{% for if in hostvars[hostname].install_cooked.interfaces %}
<interface type='bridge'>
<source bridge='{{ if.bridge }}'/>
<model type='virtio'/>
state: absent
- name: install systemd network link units
- with_items: "{{ vm_network.systemd_link.interfaces }}"
+ with_items: "{{ network.systemd_link.interfaces }}"
loop_control:
index_var: interface_index
template:
dest: "/etc/systemd/network/{{ '%02d' | format(interface_index + 11) }}-{{ item.name }}.link"
notify: rebuild initramfs
- when: vm_network.systemd_link is defined
+ when: network.systemd_link is defined
- name: install basic interface config
template:
iface lo inet loopback
# The primary network interface
-auto {{ vm_network.primary.interface }}
-iface {{ vm_network.primary.interface }} inet static
- address {{ vm_network.primary.ip }}
- netmask {{ vm_network.primary.mask }}
- gateway {{ vm_network.primary.gateway }}
+auto {{ network.primary.interface }}
+iface {{ network.primary.interface }} inet static
+ address {{ network.primary.ip }}
+ netmask {{ network.primary.mask }}
+ gateway {{ network.primary.gateway }}
pre-up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/accept_ra
pre-up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/autoconf
-{% for nsrv in vm_network.nameservers %}
+{% for nsrv in network.nameservers %}
nameserver {{ nsrv }}
{% endfor %}
-search {{ vm_network.domain }}
+search {{ network.domain }}
tasks:
- name: setup variables
set_fact:
- vm_network_cooked: "{{ vm_network }}"
- vm_install_cooked: "{{ vm_install }}"
+ network_cooked: "{{ network }}"
+ install_cooked: "{{ install }}"
- name: create temporary host group for vm host
add_host:
- name: "{{ vm_install.host }}"
+ name: "{{ vm_host }}"
inventory_dir: "{{inventory_dir}}"
group: _vmhost_
# TODO: add some sanity checks