dotfiles/config/automatrop/roles/system/tasks/main.yml

379 lines
9.3 KiB
YAML
Raw Normal View History

2023-11-02 19:51:54 +01:00
---
# TODO For other distributions
# Package are installed with --asdeps because they are needed
# Etckeeper
- name: Check if etckeeper is initialized
2023-11-02 19:51:54 +01:00
ansible.builtin.stat:
path: /etc/.git
register: etckeeper
2023-11-02 19:51:54 +01:00
become: true
- name: Initialize etckeeper
2023-11-02 19:51:54 +01:00
ansible.builtin.command: etckeeper init
become: true
when: not etckeeper.stat.exists
2023-11-02 19:51:54 +01:00
changed_when: true
- name: Configure git user.name for etckeeper
2023-11-02 19:51:54 +01:00
community.general.git_config:
scope: local
repo: /etc
name: "{{ item.name }}"
value: "{{ item.value }}"
loop:
2023-11-02 19:51:54 +01:00
- name: user.name
value: etckeeper on {{ inventory_hostname_short }}
- name: user.email
value: etckeeper@{{ inventory_hostname }}
become: true
# Manjaro configuration
- name: Remove Manjaro's pamac
2023-11-02 19:51:54 +01:00
community.general.pacman:
name: pamac
state: absent
2023-11-02 19:51:54 +01:00
become: true
when: arch_based and False # I'm trying to remember why I usually delete this thing
2021-06-21 22:01:48 +02:00
# Verbose logging during boot
- name: Check if using Uboot
2023-11-02 19:51:54 +01:00
ansible.builtin.stat:
2021-06-21 22:01:48 +02:00
path: /boot/extlinux/extlinux.conf
register: extlinux
# This (and the following) was made with the Pinebook in mind,
# not sure about compatibility
- name: Remove non-tty1 console (Uboot)
2023-11-02 19:51:54 +01:00
ansible.builtin.replace:
2021-06-21 22:01:48 +02:00
path: /boot/extlinux/extlinux.conf
2023-11-02 19:51:54 +01:00
regexp: ^APPEND(.*) console=(?!tty1)\S+(.*)$
replace: APPEND\1\2
become: true
2021-06-21 22:01:48 +02:00
when: extlinux.stat.exists
# Only one console= will be removed because regular expression are either hard
# or somewhat limited. It's just what I need anyway
- name: Remove bootsplash.bootfile (Uboot)
2023-11-02 19:51:54 +01:00
ansible.builtin.replace:
2021-06-21 22:01:48 +02:00
path: /boot/extlinux/extlinux.conf
2023-11-02 19:51:54 +01:00
regexp: ^APPEND(.*) bootsplash.bootfile=\S+(.*)$
replace: APPEND\1\2
become: true
2021-06-21 22:01:48 +02:00
when: extlinux.stat.exists
2021-06-26 14:13:05 +02:00
- name: Remove bootsplash packages (Arch based)
2023-11-02 19:51:54 +01:00
community.general.pacman:
2021-06-26 14:13:05 +02:00
name:
- bootsplash-systemd
- bootsplash-theme-manjaro
state: absent
2023-11-02 19:51:54 +01:00
become: true
2021-06-26 14:13:05 +02:00
when: arch_based
# Display Manager
- name: Remove display manager packages (Arch based)
2023-11-02 19:51:54 +01:00
community.general.pacman:
2021-06-26 14:13:05 +02:00
name:
- sddm
- sddm-breath2-theme
state: absent
2023-11-02 19:51:54 +01:00
become: true
2021-06-26 14:13:05 +02:00
when: arch_based
# Xorg configuration
- name: Check if there is nvidia-xrun is installed
2023-11-02 19:51:54 +01:00
ansible.builtin.stat:
path: /etc/X11/nvidia-xorg.conf
register: nvidia_xrun
2021-06-18 21:53:42 +02:00
when: display_server == 'x11'
- name: Add nvidia-xrun xorg config directory
2023-11-02 19:51:54 +01:00
ansible.builtin.set_fact:
xorg_common_config_dirs: "{{ xorg_default_config_dirs + xorg_nvidia_config_dirs }}"
vars:
xorg_default_config_dirs:
- /etc/X11/xorg.conf.d
xorg_nvidia_config_dirs: "{{ ['/etc/X11/nvidia-xorg.conf.d'] if nvidia_xrun.stat.exists else [] }}"
2021-06-18 21:53:42 +02:00
when: display_server == 'x11'
- name: Configure Xorg keyboard layout
2023-11-02 19:51:54 +01:00
ansible.builtin.copy:
src: xorg/keyboard.conf
dest: "{{ item }}/00-keyboard.conf"
2023-11-02 19:51:54 +01:00
become: true
2021-06-18 21:53:42 +02:00
when: display_server == 'x11'
notify: etc changed
loop: "{{ xorg_common_config_dirs }}"
- name: Use Alt keys for numpad
2023-11-02 19:51:54 +01:00
ansible.posix.patch:
src: us_qwert_alt_numpad.patch
dest: /usr/share/X11/xkb/symbols/us_qwerty-fr
2023-11-02 19:51:54 +01:00
become: true
when: display_server == 'x11'
# This is not very nice but it's updated so infrequently that it's not worth
# the trouble
- name: Check if there is Intel backlight
2023-11-02 19:51:54 +01:00
ansible.builtin.stat:
path: /sys/class/backlight/intel_backlight
register: intel_backlight
2021-06-18 21:53:42 +02:00
when: display_server == 'x11'
- name: Install Intel video drivers (Arch based)
2023-11-02 19:51:54 +01:00
community.general.pacman:
name: xf86-video-intel
# state: "{{ intel_backlight.stat.exists }}"
state: present
2023-11-02 19:51:54 +01:00
become: true
2021-06-18 21:53:42 +02:00
when: display_server == 'x11' and intel_backlight.stat.exists and arch_based
# TODO With software role? Would permit other distributions
- name: Configure Xorg Intel backlight
2023-11-02 19:51:54 +01:00
ansible.builtin.copy:
src: xorg/intel_backlight.conf
dest: "{{ item }}/20-intel_backlight.conf"
2023-11-02 19:51:54 +01:00
become: true
2021-06-18 21:53:42 +02:00
when: display_server == 'x11' and intel_backlight.stat.exists
notify: etc changed
loop: "{{ xorg_common_config_dirs }}"
- name: Configure Xorg touchpad behaviour
2023-11-02 19:51:54 +01:00
ansible.builtin.copy:
src: xorg/touchpad.conf
dest: "{{ item }}/30-touchpad.conf"
2023-11-02 19:51:54 +01:00
become: true
2021-06-18 21:53:42 +02:00
when: display_server == 'x11'
notify: etc changed
loop: "{{ xorg_common_config_dirs }}"
- name: Configure Xorg joystick behaviour
2023-11-02 19:51:54 +01:00
ansible.builtin.copy:
src: xorg/joystick.conf
dest: "{{ item }}/50-joystick.conf"
2023-11-02 19:51:54 +01:00
become: true
2021-06-18 21:53:42 +02:00
when: display_server == 'x11'
notify: etc changed
loop: "{{ xorg_common_config_dirs }}"
2021-06-21 22:01:48 +02:00
- name: List modules we're using
2023-11-02 19:51:54 +01:00
ansible.builtin.slurp:
2021-06-21 22:01:48 +02:00
src: /proc/modules
2023-11-02 19:51:54 +01:00
register: modules
2021-06-21 22:01:48 +02:00
when: display_server
# Not sure the module will be loaded in early setup stages though
- name: Make panfrost use OpenGL 3.3
2023-11-02 19:51:54 +01:00
ansible.builtin.lineinfile:
2021-06-21 22:01:48 +02:00
path: /etc/environment
2023-11-02 19:51:54 +01:00
line: PAN_MESA_DEBUG="gl3"
regexp: ^#? ?PAN_MESA_DEBUG=
become: true
2021-06-21 22:01:48 +02:00
when: display_server and using_panfrost
vars:
using_panfrost: "{{ 'panfrost' in (modules.content | b64decode) }}"
notify: panfrost config changed
# Numlock on boot
2023-11-02 19:51:54 +01:00
- name: Set numlock on boot
ansible.builtin.copy:
src: getty.service
dest: /etc/systemd/system/getty@.service.d/override.conf
2023-11-02 19:51:54 +01:00
become: true
notify:
- etc changed
- systemd changed
when: auto_numlock
- name: Unset numlock on boot
2023-11-02 19:51:54 +01:00
ansible.builtin.file:
path: /etc/systemd/system/getty@.service.d/override.conf
state: absent
2023-11-02 19:51:54 +01:00
become: true
notify:
- etc changed
- systemd changed
when: not auto_numlock
# TLP configuration
- name: Start/enable TLP
2023-11-02 19:51:54 +01:00
ansible.builtin.systemd:
name: tlp
state: started
2023-11-02 19:51:54 +01:00
enabled: true
become: true
notify: etc changed
# Network configuration
- name: Start/enable dhcpcd
2023-11-02 19:51:54 +01:00
ansible.builtin.systemd:
name: dhcpcd
state: started
2023-11-02 19:51:54 +01:00
enabled: true
become: true
notify: etc changed
- name: Configure wpa_supplicant
2023-11-02 19:51:54 +01:00
ansible.builtin.template:
src: wpa_supplicant.conf.j2
dest: /etc/wpa_supplicant/wpa_supplicant.conf
notify:
- etc changed
- wpa_supplicant changed
2023-11-02 19:51:54 +01:00
become: true
tags:
- wificonf
- name: Prepare directory for wpa_supplicant service override
2023-11-02 19:51:54 +01:00
ansible.builtin.file:
path: /etc/systemd/system/wpa_supplicant@.service.d
state: directory
2023-11-02 19:51:54 +01:00
mode: u=rwx,g=rx,o=rx
become: true
- name: Make wpa_supplicant use a common configuration file
2023-11-02 19:51:54 +01:00
ansible.builtin.copy:
src: wpa_supplicant.service
dest: /etc/systemd/system/wpa_supplicant@.service.d/override.conf
2023-11-02 19:51:54 +01:00
become: true
notify:
- etc changed
2021-06-17 21:21:34 +02:00
- systemd changed
- wifi setup changed
2021-06-17 21:21:34 +02:00
- name: Disable wpa_supplicant for networkmanager
2023-11-02 19:51:54 +01:00
ansible.builtin.systemd:
2021-06-17 21:21:34 +02:00
name: wpa_supplicant
2023-11-02 19:51:54 +01:00
enabled: false
become: true
2021-06-17 21:21:34 +02:00
notify:
- etc changed
- wifi setup changed
- name: Start/enable wpa_supplicant for interface
2023-11-02 19:51:54 +01:00
ansible.builtin.systemd:
name: wpa_supplicant@{{ item }}
enabled: true
become: true
2021-06-17 21:21:34 +02:00
notify:
- etc changed
- wifi setup changed
loop: "{{ ansible_interfaces }}"
2023-11-02 19:51:54 +01:00
when: item.startswith('wl')
# Could probably use something better like
# listing /sys/class/ieee80211/*/device/net/
2021-06-17 21:21:34 +02:00
- name: Uninstall networkmanager
2023-11-02 19:51:54 +01:00
community.general.pacman:
2021-06-17 21:21:34 +02:00
name: networkmanager
state: absent
2023-11-02 19:51:54 +01:00
extra_args: --cascade --recursive
2021-06-17 21:21:34 +02:00
when: arch_based
2023-11-02 19:51:54 +01:00
become: true
2021-06-17 21:21:34 +02:00
notify:
- wifi setup changed
2021-06-26 14:13:05 +02:00
- name: Mask systemd-networkd
2023-11-02 19:51:54 +01:00
ansible.builtin.systemd:
2021-06-26 14:13:05 +02:00
name: systemd-networkd
state: stopped
2023-11-02 19:51:54 +01:00
enabled: false
masked: true
become: true
2021-06-26 14:13:05 +02:00
notify: etc changed
# Time synchronisation
- name: Mask systemd-timesyncd
2023-11-02 19:51:54 +01:00
ansible.builtin.systemd:
name: systemd-timesyncd
state: stopped
2023-11-02 19:51:54 +01:00
enabled: false
masked: true
become: true
notify: etc changed
- name: Configure chrony
2023-11-02 19:51:54 +01:00
ansible.builtin.copy:
src: chrony.conf
dest: /etc/chrony.conf
2023-11-02 19:51:54 +01:00
become: true
notify:
- etc changed
2021-06-17 21:21:34 +02:00
- chrony reconfigured
# TODO More configuration, RTC configuration
- name: Enable chronyd
2023-11-02 19:51:54 +01:00
ansible.builtin.systemd:
name: chronyd
2023-11-02 19:51:54 +01:00
enabled: true
become: true
notify:
- etc changed
2021-06-17 21:21:34 +02:00
- chrony reconfigured
- name: Configure dhcpcd chrony hook
2023-11-02 19:51:54 +01:00
ansible.builtin.copy:
src: dhcpcd.exit-hook
dest: /etc/dhcpcd.exit-hook
2023-11-02 19:51:54 +01:00
become: true
notify: etc changed
- name: Empty motd
2023-11-02 19:51:54 +01:00
ansible.builtin.copy:
content: ""
dest: /etc/motd
2023-11-02 19:51:54 +01:00
mode: u=rw,g=r,o=r
become: true
notify:
- etc changed
2021-06-26 14:13:05 +02:00
# VPN configuration
- name: Prepare directory for openvpn-client service override
2023-11-02 19:51:54 +01:00
ansible.builtin.file:
2021-06-26 14:13:05 +02:00
path: /etc/systemd/system/openvpn-client@.service.d
state: directory
2023-11-02 19:51:54 +01:00
mode: u=rwx,g=rx,o=rx
become: true
2021-06-26 14:13:05 +02:00
- name: Make openvpn use hooks for resolvconf
2023-11-02 19:51:54 +01:00
ansible.builtin.copy:
2021-06-26 14:13:05 +02:00
src: openvpn-client.service
dest: /etc/systemd/system/openvpn-client@.service.d/override.conf
2023-11-02 19:51:54 +01:00
become: true
2021-06-26 14:13:05 +02:00
notify:
- etc changed
- systemd changed
- name: Disable power button
2023-11-02 19:51:54 +01:00
ansible.builtin.lineinfile:
path: /etc/systemd/logind.conf
2023-11-02 19:51:54 +01:00
line: HandlePowerKey=ignore
regexp: ^#? *HandlePowerKey=
insertafter: ^\[Login\]$
become: true
notify: systemd-logind config changed
# Reason: I sometimes press it accidentally
# (hoping to start it when it's already started,
# or really accidentally on the Pinebook).
# Suspend would be nice, but it doesn't have the locker then
# TODO Hibernation, if that's relevant
# $ sudo blkid | grep 'TYPE="swap"'
# $ sudoedit /etc/default/grub
# Add resume=UUID=<UUID-of-swap-partition> to GRUB_CMDLINE_LINUX_DEFAULT
# $ sudo grub-mkconfig -o /boot/grub/grub.cfg
2021-06-27 21:10:04 +02:00
# TODO udevil