This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
hostname: vm01 | |
domainname: example.com | |
gateway: 192.168.1.1 | |
dnsservers: "8.8.8.8" | |
network_name: "Network 0" | |
sr_name: "Local storage" | |
vm_template: "Debian Stretch 9.0 (64-bit)" | |
vm_name: "vm01" | |
ipaddress: 192.168.1.10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: Deploy new VM | |
command: xe vm-install template={{ templateuuid.stdout }} new-name-label="{{ vm_name }} - {{ ipaddress }} - {{ vps_type }}" sr-uuid={{ sruuid.stdout }} | |
register: vmuuid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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 }} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: Create and attach CDROM drive | |
command: xe vbd-create type=CD device=xvdd vm-uuid={{ vmuuid.stdout }} mode=ro |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: Add host to runtime inventory | |
add_host: | |
name="{{ ipaddress }}" | |
groups="deployed_vms" |