-
Notifications
You must be signed in to change notification settings - Fork 73
Allow specification of multiple VMs #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3e886a7
Add support for logging serial console to a file
markgoddard 48b2a25
Update README to reflect new API for multiple VMs
e8e3b4c
Allow specification of multiple VMs
543ac79
Ensure libvirt module tasks use `become`
0d9b954
Remove use of deprecated `success` filter
10f7947
Set boot order to hard drive, then network
2156bd3
Add default console log and iamge cache paths
e90b854
Set VM attribute defaults in main.yml
e5cf3c3
Ensure we fail if VM name, memory, vcpus not set
d7bb5b4
Don't reuse variable names in playbooks
f1683c9
Add hyphen to console log path
70bde8b
Use /var/log/libvirt-consoles/ as default log dir
397ba6f
Remove trailing whitespace in README
9ed04fd
Make console logging optional
4f92ba8
Merge pull request #1 from w-miller/console-log-file-2
w-miller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,41 @@ | ||
--- | ||
- block: | ||
- include: autodetect.yml | ||
- include: volumes.yml | ||
- include: vm.yml | ||
when: libvirt_vm_state == 'present' | ||
|
||
- block: | ||
- include: destroy-volumes.yml | ||
- include: destroy-vm.yml | ||
when: libvirt_vm_state == 'absent' | ||
- include_tasks: autodetect.yml | ||
# We need to know the engine and emulator if we're creating any new VMs. | ||
when: libvirt_vms | rejectattr('state', 'eq', 'absent') | list | ||
|
||
- include_tasks: volumes.yml | ||
vars: | ||
volumes: "{{ vm.volumes | default([], true) }}" | ||
with_items: "{{ libvirt_vms }}" | ||
loop_control: | ||
loop_var: vm | ||
when: (vm.state | default('present', true)) == 'present' | ||
|
||
- include_tasks: vm.yml | ||
vars: | ||
console_log_enabled: "{{ vm.console_log_enabled | default(false) }}" | ||
console_log_path: "{{ vm.console_log_path | default(libvirt_vm_default_console_log_dir + '/' + vm.name + '-console.log', true) }}" | ||
machine_default: "{{ none if libvirt_vm_engine == 'kvm' else 'pc-1.0' }}" | ||
machine: "{{ vm.machine | default(machine_default, true) }}" | ||
cpu_mode_default: "{{ 'host-passthrough' if libvirt_vm_engine == 'kvm' else 'host-model' }}" | ||
cpu_mode: "{{ vm.cpu_mode | default(cpu_mode_default, true) }}" | ||
volumes: "{{ vm.volumes | default([], true) }}" | ||
interfaces: "{{ vm.interfaces | default([], true) }}" | ||
with_items: "{{ libvirt_vms }}" | ||
loop_control: | ||
loop_var: vm | ||
when: (vm.state | default('present', true)) == 'present' | ||
|
||
- include_tasks: destroy-volumes.yml | ||
vars: | ||
volumes: "{{ vm.volumes | default([], true) }}" | ||
with_items: "{{ libvirt_vms }}" | ||
loop_control: | ||
loop_var: vm | ||
when: (vm.state | default('present', true)) == 'absent' | ||
|
||
- include_tasks: destroy-vm.yml | ||
with_items: "{{ libvirt_vms }}" | ||
loop_control: | ||
loop_var: vm | ||
when: (vm.state | default('present', true)) == 'absent' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,25 @@ | ||
--- | ||
- name: Ensure the VM console log directory exists | ||
file: | ||
path: "{{ console_log_path | dirname }}" | ||
state: directory | ||
owner: qemu | ||
group: qemu | ||
recurse: true | ||
mode: 0770 | ||
when: console_log_enabled | bool | ||
become: true | ||
|
||
- name: Ensure the VM is defined | ||
virt: | ||
name: "{{ libvirt_vm_name }}" | ||
name: "{{ vm.name }}" | ||
command: define | ||
xml: "{{ lookup('template', 'vm.xml.j2') }}" | ||
become: true | ||
|
||
- name: Ensure the VM is running and started at boot | ||
virt: | ||
name: "{{ libvirt_vm_name }}" | ||
name: "{{ vm.name }}" | ||
autostart: true | ||
state: running | ||
become: true |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't think the defaults will work correctly in this case, since the variable is defined - it will be None. How about just keeping the old defaults on the deprecated variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, true. It seems more consistent to use the boolean flag in the default filter for all the variables though, rather than putting some of the defaults in here.