summaryrefslogtreecommitdiff
path: root/roles/vm/guest/base/tasks/main.yml
blob: 7a383fe1d74d4a685d1d25e73035856fc1768b59 (plain) (blame)
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
---
- name: install rngd
  apt:
    name: rng-tools5
    state: present
    force_apt_get: yes

- name: get size of entropy pool
  check_mode: no
  command: cat /proc/sys/kernel/random/poolsize
  changed_when: false
  register: entropy_pool_size

- name: create systemd override directory for rngd
  file:
    path: /etc/systemd/system/rngd.service.d
    state: directory

- name: configure rngd
  copy:
    content: |
      [Service]
      ExecStart=
      ExecStart=/usr/sbin/rngd -f -r /dev/hwrng -s 256 -W {{ ((entropy_pool_size.stdout_lines | first | int) * 0.8) | int }}
    dest: /etc/systemd/system/rngd.service.d/hwrng-device.conf
  notify: restart rngd


- name: provide a root shell on the VM serial console
  when: vm_guest_autologin_on_serial
  block:
  - name: create systemd override directory for gettyS0
    file:
      path: /etc/systemd/system/serial-getty@ttyS0.service.d/
      state: directory

  - name: create autologin config for gettyS0
    copy:
      dest: /etc/systemd/system/serial-getty@ttyS0.service.d/autologon.conf
      content: |
        [Service]
        ExecStart=
        ExecStart=-/sbin/agetty --keep-baud 115200,38400,9600 --noclear --autologin root --login-pause --host {{ vm_host_cooked.name }} %I $TERM


- name: enable serial console in grub and for kernel
  vars:
    grub_options:
      GRUB_TIMEOUT: 2
      GRUB_CMDLINE_LINUX: '"console=ttyS0,115200n8"'
      GRUB_TERMINAL: serial
      GRUB_SERIAL_COMMAND: >-
        "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1"
  loop: "{{ grub_options | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  lineinfile:
    dest: /etc/default/grub
    regexp: "^{{ item.key }}="
    line: "{{ item.key }}={{ item.value }}"
  notify: update grub