ansible: vm/network role improvments
authorChristian Pointner <equinox@realraum.at>
Tue, 24 Apr 2018 19:31:16 +0000 (21:31 +0200)
committerChristian Pointner <equinox@realraum.at>
Tue, 24 Apr 2018 19:31:16 +0000 (21:31 +0200)
ansible/host_vars/testvm/main.yml
ansible/roles/vm/install/templates/libvirt-domain.xml.j2
ansible/roles/vm/install/templates/preseed_debian-stretch.cfg.j2
ansible/roles/vm/install/templates/preseed_ubuntu-xenial.cfg.j2
ansible/roles/vm/network/tasks/main.yml
ansible/roles/vm/network/templates/resolv.conf.j2 [new file with mode: 0644]
ansible/roles/vm/network/templates/systemd.link.j2

index f894adc..0709a22 100644 (file)
@@ -15,18 +15,19 @@ vm_install:
         lv: "{{ inventory_hostname }}"
         size: 10g
   interfaces:
-  - idx: 1
-    bridge: "{{ hostvars[vm_install_host].vm_host.network.interface }}"
-    name: primary0
+  - bridge: "{{ hostvars[vm_install_host].vm_host.network.interface }}"
+    name: mgmt0
+  - bridge: "br-http"
+    name: http0
   autostart: True
 
 vm_network:
+  nameservers: "{{ hostvars[vm_install_host].vm_host.network.nameservers }}"
+  domain: realraum.at
   systemd_link:
     interfaces: "{{ vm_install.interfaces }}"
   primary:
-    interface: primary0
+    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) }}"
-    nameservers: "{{ hostvars[vm_install_host].vm_host.network.nameservers }}"
-    domain: realraum.at
index 9364a7d..2bf4b57 100644 (file)
@@ -8,7 +8,7 @@
 {% if run_installer %}
     <kernel>{{ vm_host.installer.path }}/{{ vmdistro }}-{{ vmdistcodename }}/{{ hostvars[vmname].vm_install_cooked.arch | default('amd64') }}/linux</kernel>
     <initrd>{{ vm_host.installer.path }}/{{ vmdistro }}-{{ vmdistcodename }}/{{ hostvars[vmname].vm_install_cooked.arch | default('amd64') }}/initrd.gz</initrd>
-    <cmdline>console=ttyS0,115200n8 auto=true interface=auto url=tftp://{{ hostvars[inventory_hostname]['ansible_' + (vm_host.installer.net_if | replace('-', '_'))].ipv4.address }}/vm-{{ vmname }}-{{ vmdistro }}-{{ vmdistcodename }}.cfg netcfg/choose_interface=enp1s1 netcfg/disable_autoconfig=true netcfg/get_ipaddress={{ hostvars[vmname].vm_network_cooked.primary.ip }} netcfg/get_netmask={{ hostvars[vmname].vm_network_cooked.primary.mask }} netcfg/get_gateway={{ hostvars[vmname].vm_network_cooked.primary.gateway }} netcfg/get_nameservers="{{ hostvars[vmname].vm_network_cooked.primary.nameservers | join(' ') }}" netcfg/confirm_static=true netcfg/get_hostname={{ vmname }} netcfg/get_domain={{ hostvars[vmname].vm_network_cooked.primary.domain }}</cmdline>
+    <cmdline>console=ttyS0,115200n8 auto=true interface=auto url=tftp://{{ hostvars[inventory_hostname]['ansible_' + (vm_host.installer.net_if | replace('-', '_'))].ipv4.address }}/vm-{{ vmname }}-{{ vmdistro }}-{{ vmdistcodename }}.cfg netcfg/choose_interface=enp1s1 netcfg/disable_autoconfig=true netcfg/get_ipaddress={{ hostvars[vmname].vm_network_cooked.primary.ip }} netcfg/get_netmask={{ hostvars[vmname].vm_network_cooked.primary.mask }} netcfg/get_gateway={{ hostvars[vmname].vm_network_cooked.primary.gateway }} netcfg/get_nameservers="{{ hostvars[vmname].vm_network_cooked.nameservers | join(' ') }}" netcfg/confirm_static=true netcfg/get_hostname={{ vmname }} netcfg/get_domain={{ hostvars[vmname].vm_network_cooked.domain }}</cmdline>
 {% endif %}
     <boot dev='hd'/>
   </os>
@@ -55,7 +55,7 @@
     <interface type='bridge'>
       <source bridge='{{ if.bridge }}'/>
       <model type='virtio'/>
-      <address type='pci' domain='0x0000' bus='0x01' slot='0x0{{ if.idx }}' function='0x0'/>
+      <address type='pci' domain='0x0000' bus='0x01' slot='0x0{{ loop.index }}' function='0x0'/>
     </interface>
 {%   endfor %}
 {% endif %}
index 0e14edd..5b1b3f8 100644 (file)
@@ -13,11 +13,11 @@ d-i keyboard-configuration/xkb-keymap select us
 #d-i netcfg/get_ipaddress string {{ hostvars[vmname].vm_network_cooked.primary.ip }}
 #d-i netcfg/get_netmask string {{ hostvars[vmname].vm_network_cooked.primary.mask }}
 #d-i netcfg/get_gateway string {{ hostvars[vmname].vm_network_cooked.primary.gateway }}
-#d-i netcfg/get_nameservers string {{ hostvars[vmname].vm_network_cooked.primary.nameservers | join(' ') }}
+#d-i netcfg/get_nameservers string {{ hostvars[vmname].vm_network_cooked.nameservers | join(' ') }}
 #d-i netcfg/confirm_static boolean true
 
 d-i netcfg/get_hostname string {{ vmname }}
-d-i netcfg/get_domain string {{ hostvars[vmname].vm_network_cooked.primary.domain }}
+d-i netcfg/get_domain string {{ hostvars[vmname].vm_network_cooked.domain }}
 d-i netcfg/wireless_wep string
 
 
index b1c77c1..aaae381 100644 (file)
@@ -17,11 +17,11 @@ d-i keyboard-configuration/layoutcode string us
 #d-i netcfg/get_ipaddress string {{ hostvars[vmname].vm_network_cooked.primary.ip }}
 #d-i netcfg/get_netmask string {{ hostvars[vmname].vm_network_cooked.primary.mask }}
 #d-i netcfg/get_gateway string {{ hostvars[vmname].vm_network_cooked.primary.gateway }}
-#d-i netcfg/get_nameservers string {{ hostvars[vmname].vm_network_cooked.primary.nameservers | join(' ') }}
+#d-i netcfg/get_nameservers string {{ hostvars[vmname].vm_network_cooked.nameservers | join(' ') }}
 #d-i netcfg/confirm_static boolean true
 
 d-i netcfg/get_hostname string {{ vmname }}
-d-i netcfg/get_domain string {{ hostvars[vmname].vm_network_cooked.primary.domain }}
+d-i netcfg/get_domain string {{ hostvars[vmname].vm_network_cooked.domain }}
 d-i netcfg/wireless_wep string
 
 
index 6668a4c..3d51fff 100644 (file)
@@ -9,10 +9,12 @@
         state: absent
 
     - name: install systemd network link units
+      with_items: "{{ vm_network.systemd_link.interfaces }}"
+      loop_control:
+        index_var: interface_index
       template:
         src: systemd.link.j2
-        dest: "/etc/systemd/network/{{ '%02d' | format(item.idx + 10) }}-{{ item.name }}.link"
-      with_items: "{{ vm_network.systemd_link.interfaces }}"
+        dest: "/etc/systemd/network/{{ '%02d' | format(interface_index + 11) }}-{{ item.name }}.link"
       notify: rebuild initramfs
 
   when: vm_network.systemd_link is defined
     src: interfaces.j2
     dest: /etc/network/interfaces
     mode: 0644
+
+- name: remove resolvconf package
+  apt:
+    name: resolvconf
+    state: absent
+    purge: yes
+
+- name: generate resolv.conf
+  template:
+    src: resolv.conf.j2
+    dest: /etc/resolv.conf
diff --git a/ansible/roles/vm/network/templates/resolv.conf.j2 b/ansible/roles/vm/network/templates/resolv.conf.j2
new file mode 100644 (file)
index 0000000..86d4201
--- /dev/null
@@ -0,0 +1,4 @@
+{% for nsrv in vm_network.nameservers %}
+nameserver {{ nsrv }}
+{% endfor %}
+search {{ vm_network.domain }}
index 7486dfb..7093e16 100644 (file)
@@ -1,5 +1,5 @@
 [Match]
-Path=*pci-0000:01:{{ "%02d" | format(item.idx) }}.0
+Path=*pci-0000:01:{{ "%02d" | format(interface_index + 1) }}.0
 
 [Link]
 Name={{ item.name }}