Skip to content

Commit b0fa885

Browse files
authored
Merge pull request #7 from w-miller/optional-power-on
Make 'start' and 'autostart' configurable
2 parents f6832fb + fca6a4b commit b0fa885

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ Role Variables
8686
- `console_log_path`: Path to console log file. Default is
8787
`{{ libvirt_vm_default_console_log_dir }}/{{ name }}-console.log`.
8888

89+
- `start`: Whether to immediately start the VM after defining it. Default
90+
is `true`.
91+
92+
- `autostart`: Whether to start the VM when the host starts up. Default is
93+
`true`.
94+
8995

9096
N.B. the following variables are deprecated: `libvirt_vm_state`,
9197
`libvirt_vm_name`, `libvirt_vm_memory_mb`, `libvirt_vm_vcpus`,

tasks/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
cpu_mode: "{{ vm.cpu_mode | default(cpu_mode_default, true) }}"
2525
volumes: "{{ vm.volumes | default([], true) }}"
2626
interfaces: "{{ vm.interfaces | default([], true) }}"
27+
start: "{{ vm.start | default(true) }}"
28+
autostart: "{{ vm.autostart | default(true) }}"
2729
with_items: "{{ libvirt_vms }}"
2830
loop_control:
2931
loop_var: vm

tasks/vm.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
include_tasks: check-interface.yml
1515
vars:
1616
interface: "{{ item }}"
17-
with_items: "{{ vm.interfaces }}"
17+
with_items: "{{ interfaces }}"
1818

1919
- name: Ensure the VM is defined
2020
virt:
@@ -26,6 +26,6 @@
2626
- name: Ensure the VM is running and started at boot
2727
virt:
2828
name: "{{ vm.name }}"
29-
autostart: true
30-
state: running
29+
autostart: "{{ autostart | bool }}"
30+
state: "{{ 'running' if (start | bool) else 'shutdown' }}"
3131
become: true

0 commit comments

Comments
 (0)