From 7e1bccc28afd4712d9ed535593ba1dd03cc35441 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 22 Apr 2018 03:59:46 +0200 Subject: [PATCH] installer role works now but still has issues --- ansible/host_playbooks/alfred.mgmt.yml | 6 ++ ansible/host_playbooks/testvm.mgmt.yml | 7 ++ ansible/host_playbooks/testvm.yml | 7 -- ansible/host_vars/alfred.mgmt/main.yml | 27 ++++++++ ansible/host_vars/alfred/main.yml | 27 -------- ansible/host_vars/testvm.mgmt/main.yml | 32 +++++++++ ansible/host_vars/testvm/main.yml | 30 --------- ansible/hosts.ini | 6 +- ansible/remove-known-host.sh | 6 +- ansible/roles/base/tasks/main.yml | 4 +- ansible/roles/vm-install/tasks/main.yml | 68 ++++++-------------- .../vm-install/templates/libvirt-domain.xml.j2 | 26 ++++---- .../templates/preseed_debian-stretch.cfg.j2 | 31 ++++----- ansible/roles/vm-network/templates/interfaces.j2 | 10 +-- ansible/vm-install.sh | 13 +++- ansible/vm-install.yml | 39 +++++++++-- 16 files changed, 177 insertions(+), 162 deletions(-) create mode 100644 ansible/host_playbooks/alfred.mgmt.yml create mode 100644 ansible/host_playbooks/testvm.mgmt.yml delete mode 100644 ansible/host_playbooks/testvm.yml create mode 100644 ansible/host_vars/alfred.mgmt/main.yml delete mode 100644 ansible/host_vars/alfred/main.yml create mode 100644 ansible/host_vars/testvm.mgmt/main.yml delete mode 100644 ansible/host_vars/testvm/main.yml diff --git a/ansible/host_playbooks/alfred.mgmt.yml b/ansible/host_playbooks/alfred.mgmt.yml new file mode 100644 index 0000000..95d9371 --- /dev/null +++ b/ansible/host_playbooks/alfred.mgmt.yml @@ -0,0 +1,6 @@ +--- +- name: Basic Setup for alfred + hosts: alfred.mgmt + roles: + - role: base + - role: vm-host diff --git a/ansible/host_playbooks/testvm.mgmt.yml b/ansible/host_playbooks/testvm.mgmt.yml new file mode 100644 index 0000000..0640da7 --- /dev/null +++ b/ansible/host_playbooks/testvm.mgmt.yml @@ -0,0 +1,7 @@ +--- +- name: Basic Setup for testvm + hosts: testvm.mgmt + roles: + - role: base + - role: vm-grub + - role: vm-network diff --git a/ansible/host_playbooks/testvm.yml b/ansible/host_playbooks/testvm.yml deleted file mode 100644 index e79d3e3..0000000 --- a/ansible/host_playbooks/testvm.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- name: Basic Setup for server: testvm - hosts: - roles: - - role: base - - role: vm-grub - - role: vm-network diff --git a/ansible/host_vars/alfred.mgmt/main.yml b/ansible/host_vars/alfred.mgmt/main.yml new file mode 100644 index 0000000..0ade5a7 --- /dev/null +++ b/ansible/host_vars/alfred.mgmt/main.yml @@ -0,0 +1,27 @@ +--- +vm_host: + installer: + net_if: br-mgmt + preseed_path: /srv/preseed + path: /srv/installer + distros: + - distro: debian + codename: stretch + arch: + - amd64 + - i386 + - distro: ubuntu + codename: xenial + arch: + - amd64 + - i386 + network: + interface: br-mgmt + ip: 192.168.33.65 + mask: 255.255.255.0 + gateway: 192.168.33.1 + nameservers: + - 192.168.33.1 + - 10.12.0.10 + indices: + testvm.mgmt: 200 diff --git a/ansible/host_vars/alfred/main.yml b/ansible/host_vars/alfred/main.yml deleted file mode 100644 index b6b9b0c..0000000 --- a/ansible/host_vars/alfred/main.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -vm_host: - installer: - net_if: br-mgmt - preseed_path: /srv/preseed - path: /srv/installer - distros: - - distro: debian - codename: stretch - arch: - - amd64 - - i386 - - distro: ubuntu - codename: xenial - arch: - - amd64 - - i386 - network: - interface: br-mgmt - ip: 192.168.33.65 - mask: 255.255.255.0 - gateway: 192.168.33.1 - nameservers: - - 192.168.33.1 - - 10.12.0.10 - indices: - testvm: 200 diff --git a/ansible/host_vars/testvm.mgmt/main.yml b/ansible/host_vars/testvm.mgmt/main.yml new file mode 100644 index 0000000..45248e7 --- /dev/null +++ b/ansible/host_vars/testvm.mgmt/main.yml @@ -0,0 +1,32 @@ +--- +localconfig_ssh_config_user: root + +vm_install_host: alfred.mgmt + +vm_install: + host: "{{ vm_install_host }}" + mem: 1024 + numcpu: 2 + disks: + primary: vda + virtio: + vda: + vg: alfred + lv: "{{ inventory_hostname }}" + size: 10g + interfaces: + - idx: 1 + bridge: "{{ hostvars[vm_install_host].vm_host.network.interface }}" + name: primary0 + autostart: True + +vm_network: + systemd_link: + interfaces: "{{ vm_install.interfaces }}" + primary: + interface: primary0 + 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 diff --git a/ansible/host_vars/testvm/main.yml b/ansible/host_vars/testvm/main.yml deleted file mode 100644 index 479861c..0000000 --- a/ansible/host_vars/testvm/main.yml +++ /dev/null @@ -1,30 +0,0 @@ ---- -vm_install_host: alfred.mgmt - -vm_install: - host: "{{ vm_install_host }}" - mem: 1024 - numcpu: 2 - disks: - primary: vda - virtio: - vda: - vg: storage - lv: "{{ inventory_hostname }}" - size: 10g - interfaces: - - idx: 1 - bridge: "{{ hostvars[vm_install_host].vm_host.network.interface }}" - name: primary0 - autostart: True - -vm_network: - systemd_link: - interfaces: "{{ vm_install.interfaces }}" - primary: - interface: primary0 - 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 diff --git a/ansible/hosts.ini b/ansible/hosts.ini index b618973..9edea82 100644 --- a/ansible/hosts.ini +++ b/ansible/hosts.ini @@ -16,11 +16,12 @@ ctf entrance galley.mgmt hacksch.mgmt -## TODO: remove the variable once https://github.com/ansible/ansible/issues/39119 is fixed -metrics.mgmt localconfig_ssh_config_user=root r3home.mgmt tickets.mgmt vex +## TODO: remove the variable once https://github.com/ansible/ansible/issues/39119 is fixed +metrics.mgmt localconfig_ssh_config_user=root +testvm.mgmt localconfig_ssh_config_user=root [servers:children] baremetalservers @@ -38,4 +39,3 @@ wuerfel #[apu] #gnocchi1 #gnocchi2 - diff --git a/ansible/remove-known-host.sh b/ansible/remove-known-host.sh index d2c8b8d..2c5fd7f 100755 --- a/ansible/remove-known-host.sh +++ b/ansible/remove-known-host.sh @@ -5,11 +5,11 @@ if [ -z "$1" ]; then exit 1 fi -SHORT="$1" -SSH_HOST=$(ssh -G "$1" | grep "^hostname " | awk '{ print($2) }' ) +SHORT="r3-${1%%.*}" +SSH_HOST=$(ssh -G "$SHORT" | grep "^hostname " | awk '{ print($2) }' ) for name in $SHORT $SSH_HOST; do - ssh-keygen -f "$HOME/.ssh/known_hosts" -R "$name" + ssh-keygen -f "$HOME/.ssh/known_hosts" -R "[$name]:22000" done exit 0 diff --git a/ansible/roles/base/tasks/main.yml b/ansible/roles/base/tasks/main.yml index f209fe4..69b96f6 100644 --- a/ansible/roles/base/tasks/main.yml +++ b/ansible/roles/base/tasks/main.yml @@ -47,7 +47,9 @@ - name: Set authorized keys for root user authorized_key: user: root - key: "{{ lookup('pipe','cat ssh/noc/*.pub') }}" + ### TODO: this lookup doesn't work if the playbook lives in another directory + ### replace this with variables!!! + key: "{{ lookup('pipe','cat ../ssh/noc/*.pub') }}" exclusive: yes - name: disable apt suggests and recommends diff --git a/ansible/roles/vm-install/tasks/main.yml b/ansible/roles/vm-install/tasks/main.yml index 037632f..1603483 100644 --- a/ansible/roles/vm-install/tasks/main.yml +++ b/ansible/roles/vm-install/tasks/main.yml @@ -2,45 +2,39 @@ - name: generate preseed file template: src: "preseed_{{ vmdistro }}-{{ vmdistcodename }}.cfg.j2" - dest: "{{ hostvars[vm_install.host].vm_host.installer.preseed_path }}/vm-{{ inventory_hostname }}-{{ vmdistro }}-{{ vmdistcodename }}.cfg" - delegate_to: "{{ vm_install.host }}" + dest: "{{ vm_host.installer.preseed_path }}/vm-{{ vmname }}-{{ vmdistro }}-{{ vmdistcodename }}.cfg" - name: create disks for vm - with_dict: "{{ vm_install.disks.virtio | default({}) | combine(vm_install.disks.scsi | default({})) }}" + with_dict: "{{ hostvars[vmname].vm_install_cooked.disks.virtio | default({}) | combine(hostvars[vmname].vm_install_cooked.disks.scsi | default({})) }}" lvol: vg: "{{ item.value.vg }}" lv: "{{ item.value.lv }}" size: "{{ item.value.size }}" - delegate_to: "{{ vm_install.host }}" - name: check if vm already exists virt: - name: "{{ inventory_hostname }}" + name: "{{ vmname }}" command: info - delegate_to: "{{ vm_install.host }}" register: vmhost_info - name: destroy exisiting vm virt: - name: "{{ inventory_hostname }}" + name: "{{ vmname }}" state: destroyed - delegate_to: "{{ vm_install.host }}" - when: inventory_hostname in vmhost_info + when: vmname in vmhost_info - name: wait for vm to be destroyed wait_for_virt: - name: "{{ inventory_hostname }}" + name: "{{ vmname }}" states: shutdown,crashed timeout: 5 - delegate_to: "{{ vm_install.host }}" - when: inventory_hostname in vmhost_info + when: vmname in vmhost_info - name: undefining exisiting vm virt: - name: "{{ inventory_hostname }}" + name: "{{ vmname }}" command: undefine - delegate_to: "{{ vm_install.host }}" - when: inventory_hostname in vmhost_info + when: vmname in vmhost_info - name: enable installer in VM config set_fact: @@ -48,41 +42,36 @@ - name: define new installer vm virt: - name: "{{ inventory_hostname }}" + name: "{{ vmname }}" command: define xml: "{{ lookup('template', 'libvirt-domain.xml.j2') }}" - delegate_to: "{{ vm_install.host }}" - name: start vm virt: - name: "{{ inventory_hostname }}" + name: "{{ vmname }}" state: running - delegate_to: "{{ vm_install.host }}" - name: wait for installer to start wait_for_virt: - name: "{{ inventory_hostname }}" + name: "{{ vmname }}" states: running timeout: 10 - delegate_to: "{{ vm_install.host }}" - debug: - msg: "you can check on the status of the installer running this command 'virsh console {{ inventory_hostname }}' on host {{ vm_install.host }}." + msg: "you can check on the status of the installer running this command 'virsh console {{ vmname }}' on host {{ inventory_hostname }}." - name: wait for installer to finish or crash wait_for_virt: - name: "{{ inventory_hostname }}" + name: "{{ vmname }}" states: shutdown,crashed timeout: 900 - delegate_to: "{{ vm_install.host }}" register: installer_result failed_when: installer_result.failed or installer_result.state == "crashed" - name: undefining installer vm virt: - name: "{{ inventory_hostname }}" + name: "{{ vmname }}" command: undefine - delegate_to: "{{ vm_install.host }}" - name: disable installer in VM config set_fact: @@ -90,35 +79,18 @@ - name: define new production vm virt: - name: "{{ inventory_hostname }}" + name: "{{ vmname }}" command: define xml: "{{ lookup('template', 'libvirt-domain.xml.j2') }}" - delegate_to: "{{ vm_install.host }}" - name: start vm virt: - name: "{{ inventory_hostname }}" + name: "{{ vmname }}" state: running - delegate_to: "{{ vm_install.host }}" - name: mark vm as autostarted virt: - name: "{{ inventory_hostname }}" - autostart: "{{ vm_install.autostart }}" + name: "{{ vmname }}" + autostart: "{{ hostvars[vmname].vm_install_cooked.autostart }}" command: info ## virt module needs either command or state - delegate_to: "{{ vm_install.host }}" - when: vm_install.autostart is defined - - ## TODO: find a better way to fetch host key of new VMs -- name: disable ssh StrictHostKeyChecking for the next step - set_fact: - ansible_ssh_extra_args: -o StrictHostKeyChecking=no - -- name: wait for vm to start up - wait_for_connection: - delay: 5 - timeout: 120 - -- name: reenable StrictHostKeyChecking - set_fact: - ansible_ssh_extra_args: "" + when: hostvars[vmname].vm_install_cooked.autostart is defined diff --git a/ansible/roles/vm-install/templates/libvirt-domain.xml.j2 b/ansible/roles/vm-install/templates/libvirt-domain.xml.j2 index c84b104..9364a7d 100644 --- a/ansible/roles/vm-install/templates/libvirt-domain.xml.j2 +++ b/ansible/roles/vm-install/templates/libvirt-domain.xml.j2 @@ -1,14 +1,14 @@ - {{ inventory_hostname }} - {{ vm_install.mem * 1024 }} - {{ vm_install.mem * 1024 }} - {{ vm_install.numcpu }} + {{ vmname }} + {{ hostvars[vmname].vm_install_cooked.mem * 1024 }} + {{ hostvars[vmname].vm_install_cooked.mem * 1024 }} + {{ hostvars[vmname].vm_install_cooked.numcpu }} hvm {% if run_installer %} - {{ hostvars[vm_install.host].vm_host.installer.path }}/{{ vmdistro }}-{{ vmdistcodename }}/{{ vm_install.arch | default('amd64') }}/linux - {{ hostvars[vm_install.host].vm_host.installer.path }}/{{ vmdistro }}-{{ vmdistcodename }}/{{ vm_install.arch | default('amd64') }}/initrd.gz - 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 }} + {{ vm_host.installer.path }}/{{ vmdistro }}-{{ vmdistcodename }}/{{ hostvars[vmname].vm_install_cooked.arch | default('amd64') }}/linux + {{ vm_host.installer.path }}/{{ vmdistro }}-{{ vmdistcodename }}/{{ hostvars[vmname].vm_install_cooked.arch | default('amd64') }}/initrd.gz + 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 }} {% endif %} @@ -29,8 +29,8 @@ /usr/bin/kvm -{% if 'virtio' in vm_install.disks %} -{% for device, lv in vm_install.disks.virtio.items() %} +{% if 'virtio' in hostvars[vmname].vm_install_cooked.disks %} +{% for device, lv in hostvars[vmname].vm_install_cooked.disks.virtio.items() %} @@ -39,9 +39,9 @@ {% endfor %} {% endif %} -{% if 'scsi' in vm_install.disks %} +{% if 'scsi' in hostvars[vmname].vm_install_cooked.disks %} -{% for device, lv in vm_install.disks.scsi.items() %} +{% for device, lv in hostvars[vmname].vm_install_cooked.disks.scsi.items() %} @@ -50,8 +50,8 @@ {% endfor %} {% endif %} -{% if vm_install.interfaces %} -{% for if in vm_install.interfaces %} +{% if hostvars[vmname].vm_install_cooked.interfaces %} +{% for if in hostvars[vmname].vm_install_cooked.interfaces %} diff --git a/ansible/roles/vm-install/templates/preseed_debian-stretch.cfg.j2 b/ansible/roles/vm-install/templates/preseed_debian-stretch.cfg.j2 index 5e9dc9f..e8694ec 100644 --- a/ansible/roles/vm-install/templates/preseed_debian-stretch.cfg.j2 +++ b/ansible/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.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/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/confirm_static boolean true -d-i netcfg/get_hostname string {{ inventory_hostname }} -d-i netcfg/get_domain string {{ vm_network.primary.domain }} +d-i netcfg/get_hostname string {{ vmname }} +d-i netcfg/get_domain string {{ hostvars[vmname].vm_network_cooked.primary.domain }} d-i netcfg/wireless_wep string @@ -37,7 +37,7 @@ d-i time/zone string Europe/Vienna d-i clock-setup/ntp boolean false -d-i partman-auto/disk string /dev/{{ vm_install.disks.primary }} +d-i partman-auto/disk string /dev/{{ hostvars[vmname].vm_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 @@ -49,22 +49,22 @@ d-i partman-auto/expert_recipe string \ boot-root :: \ 1000 10000 -1 ext4 \ $defaultignore{ } $primary{ } $bootable{ } \ - method{ lvm } vg_name{ {{ inventory_hostname }} } \ + method{ lvm } vg_name{ {{ vmname }} } \ . \ 2048 10000 2560 ext4 \ - $lvmok{ } in_vg{ {{ inventory_hostname }} } \ + $lvmok{ } in_vg{ {{ vmname }} } \ method{ format } format{ } \ use_filesystem{ } filesystem{ ext4 } \ mountpoint{ / } \ . \ 1024 11000 1280 ext4 \ - $lvmok{ } in_vg{ {{ inventory_hostname }} } \ + $lvmok{ } in_vg{ {{ vmname }} } \ method{ format } format{ } \ use_filesystem{ } filesystem{ ext4 } \ mountpoint{ /var } \ . \ 768 10000 768 ext4 \ - $lvmok{ } in_vg{ {{ inventory_hostname }} } \ + $lvmok{ } in_vg{ {{ vmname }} } \ method{ format } format{ } \ use_filesystem{ } filesystem{ ext4 } \ mountpoint{ /var/log } \ @@ -72,7 +72,7 @@ d-i partman-auto/expert_recipe string \ options/noexec{ noexec } \ . \ 16 20000 -1 ext4 \ - $lvmok{ } in_vg{ {{ inventory_hostname }} } \ + $lvmok{ } in_vg{ {{ vmname }} } \ method( keep } lv_name{ dummy } \ . @@ -92,7 +92,7 @@ d-i pkgsel/include string openssh-server python d-i pkgsel/upgrade select safe-upgrade popularity-contest popularity-contest/participate boolean false -d-i grub-installer/choose_bootdev string /dev/{{ vm_install.disks.primary }} +d-i grub-installer/choose_bootdev string /dev/{{ hostvars[vmname].vm_install_cooked.disks.primary }} d-i grub-installer/only_debian boolean true d-i grub-installer/with_other_os boolean false @@ -100,6 +100,7 @@ d-i finish-install/reboot_in_progress note d-i preseed/late_command string \ - lvremove -f {{ inventory_hostname }}/dummy; \ + lvremove -f {{ vmname }}/dummy; \ in-target bash -c "apt-get update -q && apt-get full-upgrade -y -q"; \ - 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" + in-target bash -c "passwd -d root; passwd -l root; umask 077; mkdir -p /root/.ssh/; echo -e '{{ lookup('pipe','cat ssh/noc/*.pub') | replace('\n', '\\n') }}' > /root/.ssh/authorized_keys"; \ + in-target bash -c "sed 's/^\(\s*#\s*Port.*\)/Port 22000/' -i /etc/ssh/sshd_config" diff --git a/ansible/roles/vm-network/templates/interfaces.j2 b/ansible/roles/vm-network/templates/interfaces.j2 index 9092a0b..542e18d 100644 --- a/ansible/roles/vm-network/templates/interfaces.j2 +++ b/ansible/roles/vm-network/templates/interfaces.j2 @@ -8,10 +8,10 @@ auto lo iface lo inet loopback # The primary network interface -auto {{ srv_network.primary.interface }} -iface {{ srv_network.primary.interface }} inet static - address {{ srv_network.primary.ip }} - netmask {{ srv_network.primary.mask }} - gateway {{ srv_network.primary.gateway }} +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 }} pre-up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/accept_ra pre-up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/autoconf diff --git a/ansible/vm-install.sh b/ansible/vm-install.sh index 428fdb5..0cc0be4 100755 --- a/ansible/vm-install.sh +++ b/ansible/vm-install.sh @@ -5,12 +5,19 @@ if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then exit 1 fi -echo "installing vm: $1 with $2/$3" +name=$1 +shift +distro=$1 +shift +codename=$1 +shift + +echo "installing vm: $name with $distro/$codename" echo "" echo "########## clearing old ssh host keys #########" -./remove-known-host.sh "$1" +./remove-known-host.sh "$name" echo "" echo "######## running the install playbook ########" -exec ansible-playbook -e "vmname=$1" -e "vmdistro=$2" -e "vmdistcodename=$3" vm-install.yml +exec ansible-playbook -e "vmname=$name" -e "vmdistro=$distro" -e "vmdistcodename=$codename" $@ vm-install.yml diff --git a/ansible/vm-install.yml b/ansible/vm-install.yml index e82aa33..198b26f 100644 --- a/ansible/vm-install.yml +++ b/ansible/vm-install.yml @@ -1,18 +1,43 @@ --- -- name: Basic Installation +- name: preperations and sanity checks hosts: "{{ vmname }}" gather_facts: no - pre_tasks: - - name: Gather facts of vm host - setup: - delegate_to: "{{ vm_install.host }}" - delegate_facts: yes + tasks: + - name: setup variables + set_fact: + vm_network_cooked: "{{ vm_network }}" + vm_install_cooked: "{{ vm_install }}" + - name: create temporary host group for vm host + add_host: + name: "{{ vm_install.host }}" + inventory_dir: "{{inventory_dir}}" + group: _vmhost_ + # TODO: add some sanity checks + +- name: basic installation + hosts: _vmhost_ roles: - role: vm-install +- name: wait for new vm to start up + hosts: "{{ vmname }}" + gather_facts: no + tasks: + ## TODO: find a better way to fetch host key of new VMs + - name: disable ssh StrictHostKeyChecking for the next step + set_fact: + ansible_ssh_extra_args: -o StrictHostKeyChecking=no + - name: wait for vm to start up + wait_for_connection: + delay: 5 + timeout: 120 + - name: reenable StrictHostKeyChecking + set_fact: + ansible_ssh_extra_args: "" + - import_playbook: "host_playbooks/{{ vmname }}.yml" -- name: Reboot and wait for VM come back +- name: reboot and wait for VM come back hosts: "{{ vmname }}" gather_facts: no roles: -- 1.7.10.4