Skip to content

Commit 4f92ba8

Browse files
authored
Merge pull request #1 from w-miller/console-log-file-2
Console log file enabled toggle
2 parents 70bde8b + 9ed04fd commit 4f92ba8

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

README.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,39 @@ Role Variables
3232

3333
- `state`: set to `present` to create or `absent` to destroy the VM.
3434
Defaults to `present`.
35-
35+
3636
- `name`: the name to assign to the VM.
37-
37+
3838
- `memory_mb`: the memory to assign to the VM, in megabytes.
39-
39+
4040
- `vcpus`: the number of VCPU cores to assign to the VM.
41-
41+
4242
- `machine`: Virtual machine type. Default is `None` if
4343
`libvirt_vm_engine` is `kvm`, otherwise `pc-1.0`.
44-
44+
4545
- `cpu_mode`: Virtual machine CPU mode. Default is `host-passthrough` if
4646
`libvirt_vm_engine` is `kvm`, otherwise `host-model`.
47-
47+
4848
- `volumes`: a list of volumes to attach to the VM. Each volume is
4949
defined with the following dict:
5050
- `name`: Name to associate with the volume being created.
51-
- `device`: `disk`
51+
- `device`: `disk`
5252
- `format`: options include `raw`, `qcow2`, `vmdk`. See `man virsh` for the
53-
full range. Default is `qcow2`
53+
full range. Default is `qcow2`
5454
- `capacity`: volume capacity (can be suffixed with M,G,T or MB,GB,TB, etc)
5555
- `image`: (optional) a URL to an image with which the volume is initalised.
5656
- `pool`: Name or UUID of the storage pool from which the volume should be
5757
allocated.
58-
58+
5959
- `interfaces`: a list of network interfaces to attach to the VM.
6060
Each network interface is defined with the following dict:
6161
- `network`: Name of the network to which an interface should be attached.
62-
62+
63+
- `console_log_enabled`: if `true`, log console output to a file at the
64+
path specified by `console_log_path`, **instead of** to a PTY. If
65+
`false`, direct terminal output to a PTY at serial port 0. Default is
66+
`false`.
67+
6368
- `console_log_path`: Path to console log file. Default is
6469
`{{ libvirt_vm_default_console_log_dir }}/{{ name }}-console.log`.
6570

tasks/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
- include_tasks: vm.yml
1515
vars:
16+
console_log_enabled: "{{ vm.console_log_enabled | default(false) }}"
1617
console_log_path: "{{ vm.console_log_path | default(libvirt_vm_default_console_log_dir + '/' + vm.name + '-console.log', true) }}"
1718
machine_default: "{{ none if libvirt_vm_engine == 'kvm' else 'pc-1.0' }}"
1819
machine: "{{ vm.machine | default(machine_default, true) }}"

tasks/vm.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
group: qemu
88
recurse: true
99
mode: 0770
10+
when: console_log_enabled | bool
1011
become: true
1112

1213
- name: Ensure the VM is defined

templates/vm.xml.j2

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,22 @@
3131
<model type='virtio'/>
3232
</interface>
3333
{% endfor %}
34-
<serial type='file'>
35-
<source path='{{ console_log_path }}'/>
36-
</serial>
37-
<serial type='pty'/>
38-
<console type='file'>
39-
<source path='{{ console_log_path }}'/>
40-
<target type='serial'/>
41-
</console>
34+
{% if console_log_enabled | bool %}
35+
<serial type='file'>
36+
<source path='{{ console_log_path }}'/>
37+
</serial>
38+
<serial type='pty'/>
39+
<console type='file'>
40+
<source path='{{ console_log_path }}'/>
41+
<target type='serial'/>
42+
</console>
43+
{% else %}
44+
<serial type='pty'>
45+
<target port='0'/>
46+
</serial>
47+
<console type='pty'>
48+
<target type='serial' port='0'/>
49+
</console>
50+
{% endif %}
4251
</devices>
4352
</domain>

0 commit comments

Comments
 (0)