diff --git a/README.md b/README.md index 9e83dc9..8a6bd6c 100644 --- a/README.md +++ b/README.md @@ -252,6 +252,7 @@ These variable are optional, there are sensible defaults set up, most of them ca * **cpu:** `optional`. Specify the cpu number for the VM. If not specified, the default value is taken. Default: `1` * **memory:** `optional`. Specify the memory ram for the VM. If not specified, the default value is taken. Default: `1024` * **set_new_password:** `optional`. Specify a new password to access the Vm. If not specified, the default value (**ssh_password**) is taken. +* **vm_autoboot**: `optional`. Specify if the VM should be automatically started at boot. Default: `False` ### Terraform Node, Bastions & Jumphosts @@ -650,4 +651,4 @@ will be restored and saved on each run. - GNU GPLv3, See LICENSE file. -[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2F89luca89%2Fterrible.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2F89luca89%2Fterrible?ref=badge_large) \ No newline at end of file +[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2F89luca89%2Fterrible.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2F89luca89%2Fterrible?ref=badge_large) diff --git a/inventory-example.yml b/inventory-example.yml index ee1dfc6..bd823ad 100644 --- a/inventory-example.yml +++ b/inventory-example.yml @@ -87,6 +87,10 @@ all: cpu: 4 memory: 1024 + # Whether to autostart the VM with the hypervisor or not. + # Defaults to false + vm_autostart: True + ## Hypervisor # this variable is required and decides on which hypervisor # the VM should be deployed, this value should be the inventory_hostname @@ -278,6 +282,7 @@ all: host-vm-2: os_family: RedHat hypervisor: hypervisor_1 + vm_autostart: False ansible_host: 192.168.122.200 network_interfaces: iface_1: diff --git a/roles/terrible/defaults/main.yml b/roles/terrible/defaults/main.yml index 8c07e19..88c3111 100644 --- a/roles/terrible/defaults/main.yml +++ b/roles/terrible/defaults/main.yml @@ -6,6 +6,7 @@ cpu: 1 memory: 1024 network_name: "default" +vm_autostart: False terraform_version: 0.12 diff --git a/roles/terrible/templates/terraform-vm.tf.j2 b/roles/terrible/templates/terraform-vm.tf.j2 index 9b19dbc..961c950 100644 --- a/roles/terrible/templates/terraform-vm.tf.j2 +++ b/roles/terrible/templates/terraform-vm.tf.j2 @@ -38,6 +38,8 @@ resource "libvirt_domain" "domain_{{ inventory_hostname }}" { memory = {{ memory }} vcpu = {{ cpu }} + autostart = {% if vm_autostart %}true{% else %}false{% endif %} + cpu = { mode = "host-passthrough" }