Skip to content

Commit

Permalink
Merge pull request #7 from w-miller/optional-power-on
Browse files Browse the repository at this point in the history
Make 'start' and 'autostart' configurable
  • Loading branch information
markgoddard authored Sep 11, 2018
2 parents f6832fb + fca6a4b commit b0fa885
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ Role Variables
- `console_log_path`: Path to console log file. Default is
`{{ libvirt_vm_default_console_log_dir }}/{{ name }}-console.log`.

- `start`: Whether to immediately start the VM after defining it. Default
is `true`.

- `autostart`: Whether to start the VM when the host starts up. Default is
`true`.


N.B. the following variables are deprecated: `libvirt_vm_state`,
`libvirt_vm_name`, `libvirt_vm_memory_mb`, `libvirt_vm_vcpus`,
Expand Down
2 changes: 2 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
cpu_mode: "{{ vm.cpu_mode | default(cpu_mode_default, true) }}"
volumes: "{{ vm.volumes | default([], true) }}"
interfaces: "{{ vm.interfaces | default([], true) }}"
start: "{{ vm.start | default(true) }}"
autostart: "{{ vm.autostart | default(true) }}"
with_items: "{{ libvirt_vms }}"
loop_control:
loop_var: vm
Expand Down
6 changes: 3 additions & 3 deletions tasks/vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
include_tasks: check-interface.yml
vars:
interface: "{{ item }}"
with_items: "{{ vm.interfaces }}"
with_items: "{{ interfaces }}"

- name: Ensure the VM is defined
virt:
Expand All @@ -26,6 +26,6 @@
- name: Ensure the VM is running and started at boot
virt:
name: "{{ vm.name }}"
autostart: true
state: running
autostart: "{{ autostart | bool }}"
state: "{{ 'running' if (start | bool) else 'shutdown' }}"
become: true

0 comments on commit b0fa885

Please sign in to comment.