Skip to content

Commit 9ed04fd

Browse files
author
Will Miller
committed
Make console logging optional
Logging the console to a file prevents a serial PTY from also being available, which is not ideal. Add a toggle to enable console logging which defaults to false, meaning the old PTY behaviour is maintained by default.
1 parent 397ba6f commit 9ed04fd

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ Role Variables
6060
Each network interface is defined with the following dict:
6161
- `network`: Name of the network to which an interface should be attached.
6262

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)