-
Notifications
You must be signed in to change notification settings - Fork 19
/
install_qemu_guest_agent_on_truenas.yml
104 lines (94 loc) · 3.54 KB
/
install_qemu_guest_agent_on_truenas.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
- name: Change host variable
hosts: localhost
connection: local
tasks:
- name: Use hostname from env var working_host
ansible.builtin.add_host:
name: "{{ working_host }}"
groups: working_group
tags:
- always
- name: TrueNAS QEMU Guest Agent Setup
hosts: working_group
gather_facts: true
remote_user: root
vars:
# ansible_python_interpreter: /usr/bin/python
ansible_ssh_port: 22
ansible_ssh_common_args: '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
freebsd13_kernel: "http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/amd64/13.1-RELEASE/kernel.txz"
freebsd13_qga_pkg: "https://pkg.freebsd.org/FreeBSD:13:amd64/latest/All/qemu-guest-agent-8.1.3.pkg"
qga_backup_dir: "/root/qga_backup"
tasks:
- name: Download FreeBSD 13.1 kernel.txz to /tmp
ansible.builtin.get_url:
url: "{{ freebsd13_kernel }}"
dest: /tmp/kernel.txz
mode: '0644'
register: fetch_kernel
failed_when: fetch_kernel is failed
tags:
- fetch_kernel
- name: Extract kernel.txz to /tmp
ansible.builtin.shell: |
tar -xf /tmp/kernel.txz --strip-components=3 -C /boot/modules/ ./boot/kernel/virtio_console.ko
register: extract_kernel
failed_when: extract_kernel is failed
tags:
- extract_kernel
- name: Load VirtIO Console driver
ansible.builtin.shell: |
kldload /boot/modules/virtio_console.ko
register: load_kernel
failed_when: load_kernel is failed
tags:
- load_kernel
- name: Download and Install downloaded FreeBSD 13 QEMU Guest Agent package
ansible.builtin.shell: |
IGNORE_OSVERSION=yes pkg add {{ freebsd13_qga_pkg }}
args:
executable: /bin/bash
register: install_qga
failed_when: install_qga is failed
tags:
- install_qga
- name: Create backup of qemu-guest-agent file
ansible.builtin.shell: |
mkdir {{ qga_backup_dir }}
cp /usr/local/etc/rc.d/qemu-guest-agent {{ qga_backup_dir }}/qemu-guest-agent
args:
executable: /bin/bash
register: backup_qga
failed_when: backup_qga is failed
tags:
- backup_qga
- name: Create Tunables for QEMU Guest Agent
ansible.builtin.shell: |
cli <<EOF
system tunable create type=RC var="qemu_guest_agent_enable" value="YES" enabled=true
system tunable create type=RC var="qemu_guest_agent_flags" value="-d -v -l /var/log/qemu-ga.log" enabled=true
system tunable create type=LOADER var="virtio_console_load" value="YES" enabled=true
EOF
args:
executable: /bin/bash
register: create_tunables
failed_when: create_tunables is failed
tags:
- create_tunables
- name: Set un init/shutdown Scripts
ansible.builtin.shell: |
cli << EOF
system initshutdownscript create type=COMMAND command="service qemu-guest-agent start" when=POSTINIT enabled=true timeout=10 comment="start qemu-guest-agent on boot"
system initshutdownscript create type=COMMAND command="cp {{ qga_backup_dir }}/qemu-guest-agent /usr/local/etc/rc.d" when=PREINIT enabled=true timeout=10 comment="copy qemu-guest-agent on boot"
EOF
args:
executable: /bin/bash
register: create_scripts
failed_when: create_scripts is failed
tags:
- create_scripts
- name: Print message
ansible.builtin.debug:
msg: "Please reboot TrueNAS to apply changes."
tags:
- reboot_message