Skip to content

Commit 3e886a7

Browse files
committed
Add support for logging serial console to a file
1 parent da56e8c commit 3e886a7

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ allocated.
5050
Each network interface is defined with the following dict:
5151
- `network`: Name of the network to which an interface should be attached.
5252

53+
`libvirt_vm_console_log_path`: Path to console log file. Default is
54+
`/var/log/libvirt/qemu/{{ libvirt_vm_name }}-console.log`.
55+
5356
`libvirt_vm_image_cache_path`: path to cache downloaded images.
5457

5558
Dependencies

defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ libvirt_vm_volumes: []
3434
# List of network interfaces.
3535
libvirt_vm_interfaces: []
3636

37+
# Path to console log file.
38+
libvirt_vm_console_log_path: "/var/log/libvirt-consoles/{{ libvirt_vm_name }}.log"
39+
3740
# Path to cache downloaded images.
3841
libvirt_vm_image_cache_path:
3942

tasks/vm.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
---
2+
- name: Ensure the VM console log directory exists
3+
file:
4+
path: "{{ libvirt_vm_console_log_path | dirname }}"
5+
state: directory
6+
owner: qemu
7+
group: qemu
8+
recurse: true
9+
mode: 0770
10+
become: true
11+
212
- name: Ensure the VM is defined
313
virt:
414
name: "{{ libvirt_vm_name }}"

templates/vm.xml.j2

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
<model type='virtio'/>
2727
</interface>
2828
{% endfor %}
29-
<serial type='pty'>
30-
<target port='0'/>
29+
<serial type='file'>
30+
<source path='{{ libvirt_vm_console_log_path }}'/>
3131
</serial>
32-
<console type='pty'>
33-
<target type='serial' port='0'/>
32+
<serial type='pty'/>
33+
<console type='file'>
34+
<source path='{{ libvirt_vm_console_log_path }}'/>
35+
<target type='serial'/>
3436
</console>
3537
</devices>
3638
</domain>

0 commit comments

Comments
 (0)