Skip to content

Instantly share code, notes, and snippets.

View jrisch's full-sized avatar
🏠
Working from home

Juri Rischel Jensen jrisch

🏠
Working from home
View GitHub Profile
#### Contents of the preconfiguration file (for stretch)
### Localization
# Preseeding only locale sets language, country and locale.
#d-i debian-installer/locale string en_US
# The values can also be preseeded individually for greater flexibility.
d-i debian-installer/language string en
d-i debian-installer/country string DK
d-i debian-installer/locale string en_DK.UTF-8
# Optionally specify additional locales to be generated.
- name: Install Xentools on deployed vm
hosts: deployed_vms
tasks:
- name: Mount xentools CD
command: mount /dev/xvdd /mnt
- name: Run the xentools installer
command: /mnt/Linux/install.sh -n
- name: Add host to runtime inventory
add_host:
name="{{ ipaddress }}"
groups="deployed_vms"
- name: Insert Xentools CD in CDROM drive
command: xe vm-cd-insert cd-name=xs-tools.iso vm={{ vmuuid.stdout }}
when: ansible_distribution_major_version|int <= 6
- name: Insert Xentools CD in CDROM drive
command: xe vm-cd-insert cd-name=guest-tools.iso vm={{ vmuuid.stdout }}
when: ansible_distribution_major_version|int >= 7
- name: Get the last boot time for the VM
command: xe vm-param-get param-name=start-time uuid={{ vmuuid.stdout}}
- name: Boot VM and start preseed installation
command: xe vm-start uuid={{ vmuuid.stdout }}
- name: Get the boot time for the VM
command: xe vm-param-get param-name=start-time uuid={{ vmuuid.stdout}}
register: boottime
- name: Watch for the first reboot
shell: export starttime={{ boottime.stdout }}; while [[ ${starttime} == {{ boottime.stdout }} ]]; do sleep 15; starttime=`xe vm-param-get param-name=start-time uuid={{ vmuuid.stdout }}`; done
async: 1800
- name: Create and attach CDROM drive
command: xe vbd-create type=CD device=xvdd vm-uuid={{ vmuuid.stdout }} mode=ro
- name: Load bootargs and install repo for Debian install
include_vars:
file=group_vars/Debian.yml
when: '"Debian" in vm_template'
- name: Load bootargs and install repo for Ubuntu install
include_vars:
file=group_vars/Ubuntu.yml
when: '"Ubuntu" in vm_template'
- name: Set memory
command: xe vm-memory-limits-set uuid={{ vmuuid.stdout }} dynamic-min="{{ memory }}" dynamic-max="{{ memory }}" static-max="{{ memory }}" static-min="{{ memory }}"
- name: Attach VM to {{ network_name }}
command: xe vif-create vm-uuid={{ vmuuid.stdout }} network-uuid={{ networkuuid.stdout }} mac=random device=0
- name: Get the UUID of the disk
command: xe vm-disk-list vbd-params=device=xvda uuid={{ vmuuid.stdout }} --minimal
register: vdiuuid
- name: Set disk size
command: xe vdi-resize disk-size="{{ disksize }}" uuid={{ vdiuuid.stdout }}
- name: Set vcpu priority
command: xe vm-param-set VCPUs-params:weight={{ cpu_weight }} uuid={{ vmuuid.stdout }}
- name: Set vcpu count max
command: xe vm-param-set VCPUs-max={{ vcpu_count }} uuid={{ vmuuid.stdout }}
when: vcpu_count >= "2"
- name: Set vcpu count at startup
command: xe vm-param-set VCPUs-at-startup={{ vcpu_count }} uuid={{ vmuuid.stdout }}
when: vcpu_count >= "2"