350 lines
7.8 KiB
YAML
350 lines
7.8 KiB
YAML
# TODO For other distributions
|
|
|
|
- name: Set variables
|
|
set_fact:
|
|
arch_based: "{{ ansible_distribution == 'Archlinux' }}"
|
|
# arch: "{{ ansible_lsb.id == 'Arch' }}"
|
|
# manjaro: "{{ ansible_lsb.id == 'Manjaro' or ansible_lsb.id == 'Manjaro-ARM' }}"
|
|
# termux: "{{ ansible_distribution == 'OtherLinux' and ansible_python.executable == '/data/data/com.termux/files/usr/bin/python' }}"
|
|
# debian_based: "{{ ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' }}"
|
|
# debian: "{{ ansible_distribution == 'Debian' }}"
|
|
# ubuntu: "{{ ansible_distribution == 'Ubuntu' }}"
|
|
|
|
# Etckeeper
|
|
|
|
- name: Install etckeeper (Arch based)
|
|
pacman:
|
|
name: etckeeper
|
|
state: present
|
|
become: yes
|
|
when: arch_based
|
|
|
|
- name: Check if etckeeper is initialized
|
|
stat:
|
|
path: /etc/.git
|
|
register: etckeeper
|
|
become: yes
|
|
|
|
- name: Initialize etckeeper
|
|
command: "etckeeper init"
|
|
become: yes
|
|
when: not etckeeper.stat.exists
|
|
changed_when: yes
|
|
|
|
- name: Configure git user.name for etckeeper
|
|
git_config:
|
|
scope: local
|
|
repo: /etc
|
|
name: "{{ item.name }}"
|
|
value: "{{ item.value }}"
|
|
loop:
|
|
- name: "user.name"
|
|
value: "etckeeper on {{ inventory_hostname_short }}"
|
|
- name: "user.email"
|
|
value: "etckeeper@{{ inventory_hostname }}"
|
|
become: yes
|
|
|
|
# Arch configuration
|
|
|
|
- name: Install ccache
|
|
pacman:
|
|
name: ccache
|
|
state: present
|
|
become: yes
|
|
when: arch_based
|
|
|
|
- name: Enable makepkg ccache
|
|
replace:
|
|
path: /etc/makepkg.conf
|
|
regexp: '^BUILDENV=(.+)!ccache(.+)$'
|
|
replace: 'BUILDENV=\1ccache\2'
|
|
become: yes
|
|
when: arch_based
|
|
|
|
- name: Set makepkg MAKEFLAGS
|
|
replace:
|
|
path: /etc/makepkg.conf
|
|
regexp: '^#? *MAKEFLAGS=(.+)-j[0-9]+(.+)$'
|
|
replace: "MAKEFLAGS=\\1-j{{ j }}\\2"
|
|
become: yes
|
|
vars:
|
|
j: "{{ [ansible_processor_nproc - 1, 1] | max | int }}"
|
|
when: arch_based
|
|
|
|
- name: Enable makepkg color
|
|
replace:
|
|
path: /etc/makepkg.conf
|
|
regexp: '^BUILDENV=(.+)!color(.+)$'
|
|
replace: 'BUILDENV=\1color\2'
|
|
become: yes
|
|
when: arch_based
|
|
|
|
- name: Enable pacman colors
|
|
lineinfile:
|
|
path: /etc/pacman.conf
|
|
regexp: "^#?Color"
|
|
line: "Color"
|
|
become: yes
|
|
when: arch_based
|
|
|
|
- name: Enable pacman pacman
|
|
lineinfile:
|
|
path: /etc/pacman.conf
|
|
regexp: "^#?ILoveCandy"
|
|
line: "ILoveCandy"
|
|
insertafter: "^#?Color"
|
|
become: yes
|
|
when: arch_based
|
|
|
|
# Manjaro configuration
|
|
|
|
- name: Remove Manjaro's pamac
|
|
pacman:
|
|
name: pamac
|
|
state: absent
|
|
become: yes
|
|
when: arch_based and False # I'm trying to remember why I usually delete this thing
|
|
|
|
# Xorg configuration
|
|
|
|
- name: Check if there is nvidia-xrun is installed
|
|
stat:
|
|
path: /etc/X11/nvidia-xorg.conf
|
|
register: nvidia_xrun
|
|
when: display_server == 'x11'
|
|
|
|
- name: Add nvidia-xrun xorg config directory
|
|
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 [] }}"
|
|
when: display_server == 'x11'
|
|
|
|
- name: Configure Xorg keyboard layout
|
|
copy:
|
|
src: xorg/keyboard.conf
|
|
dest: "{{ item }}/00-keyboard.conf"
|
|
become: yes
|
|
when: display_server == 'x11'
|
|
notify: etc changed
|
|
loop: "{{ xorg_common_config_dirs }}"
|
|
|
|
- name: Check if there is Intel backlight
|
|
stat:
|
|
path: /sys/class/backlight/intel_backlight
|
|
register: intel_backlight
|
|
when: display_server == 'x11'
|
|
|
|
- name: Install Intel video drivers (Arch based)
|
|
pacman:
|
|
name: xf86-video-intel
|
|
# state: "{{ intel_backlight.stat.exists }}"
|
|
state: present
|
|
become: yes
|
|
when: display_server == 'x11' and intel_backlight.stat.exists and arch_based
|
|
|
|
- name: Configure Xorg Intel backlight
|
|
copy:
|
|
src: xorg/intel_backlight.conf
|
|
dest: "{{ item }}/20-intel_backlight.conf"
|
|
become: yes
|
|
when: display_server == 'x11' and intel_backlight.stat.exists
|
|
notify: etc changed
|
|
loop: "{{ xorg_common_config_dirs }}"
|
|
|
|
- name: Configure Xorg touchpad behaviour
|
|
copy:
|
|
src: xorg/touchpad.conf
|
|
dest: "{{ item }}/30-touchpad.conf"
|
|
become: yes
|
|
when: display_server == 'x11'
|
|
notify: etc changed
|
|
loop: "{{ xorg_common_config_dirs }}"
|
|
|
|
- name: Configure Xorg joystick behaviour
|
|
copy:
|
|
src: xorg/joystick.conf
|
|
dest: "{{ item }}/50-joystick.conf"
|
|
become: yes
|
|
when: display_server == 'x11'
|
|
notify: etc changed
|
|
loop: "{{ xorg_common_config_dirs }}"
|
|
|
|
# Numlock on boot
|
|
|
|
- name: set numlock on boot
|
|
copy:
|
|
src: getty.service
|
|
dest: /etc/systemd/system/getty@.service.d/override.conf
|
|
become: yes
|
|
notify:
|
|
- etc changed
|
|
- systemd changed
|
|
when: auto_numlock
|
|
|
|
- name: Unset numlock on boot
|
|
file:
|
|
path: /etc/systemd/system/getty@.service.d/override.conf
|
|
state: absent
|
|
become: yes
|
|
notify:
|
|
- etc changed
|
|
- systemd changed
|
|
when: not auto_numlock
|
|
|
|
# TLP configuration
|
|
|
|
- name: Install TLP (Arch based)
|
|
pacman:
|
|
name: tlp
|
|
state: present
|
|
when: arch_based
|
|
become: yes
|
|
|
|
- name: Start/enable TLP
|
|
systemd:
|
|
name: tlp
|
|
state: started
|
|
enabled: yes
|
|
become: yes
|
|
notify: etc changed
|
|
|
|
# Network configuration
|
|
|
|
- name: Install dhcpcd (Arch based)
|
|
pacman:
|
|
name: dhcpcd
|
|
state: present
|
|
when: arch_based
|
|
become: yes
|
|
|
|
- name: Start/enable dhcpcd
|
|
systemd:
|
|
name: dhcpcd
|
|
state: started
|
|
enabled: yes
|
|
become: yes
|
|
notify: etc changed
|
|
|
|
- name: Install wpa_supplicant (Arch based)
|
|
pacman:
|
|
name: wpa_supplicant
|
|
state: present
|
|
when: arch_based
|
|
become: yes
|
|
notify:
|
|
- wifi setup changed
|
|
|
|
- name: Configure wpa_supplicant
|
|
template:
|
|
src: wpa_supplicant.conf.j2
|
|
dest: /etc/wpa_supplicant/wpa_supplicant.conf
|
|
notify:
|
|
- etc changed
|
|
- wpa_supplicant changed
|
|
become: yes
|
|
tags:
|
|
- wificonf
|
|
|
|
- name: Prepare directory for wpa_supplicant service override
|
|
file:
|
|
path: /etc/systemd/system/wpa_supplicant@.service.d
|
|
state: directory
|
|
mode: "u=rwx,g=rx,o=rx"
|
|
become: yes
|
|
|
|
- name: Make wpa_supplicant use a common configuration file
|
|
copy:
|
|
src: wpa_supplicant.service
|
|
dest: /etc/systemd/system/wpa_supplicant@.service.d/override.conf
|
|
become: yes
|
|
notify:
|
|
- etc changed
|
|
- systemd changed
|
|
- wifi setup changed
|
|
|
|
- name: Disable wpa_supplicant for networkmanager
|
|
systemd:
|
|
name: wpa_supplicant
|
|
enabled: no
|
|
become: yes
|
|
notify:
|
|
- etc changed
|
|
- wifi setup changed
|
|
|
|
- name: Start/enable wpa_supplicant for interface
|
|
systemd:
|
|
name: "wpa_supplicant@{{ item }}"
|
|
enabled: yes
|
|
become: yes
|
|
notify:
|
|
- etc changed
|
|
- wifi setup changed
|
|
loop: "{{ ansible_interfaces }}"
|
|
when: "item.startswith('wl')"
|
|
# Could probably use something better like
|
|
# listing /sys/class/ieee80211/*/device/net/
|
|
|
|
- name: Uninstall networkmanager
|
|
pacman:
|
|
name: networkmanager
|
|
state: absent
|
|
extra_args: "--cascade --recursive"
|
|
when: arch_based
|
|
become: yes
|
|
notify:
|
|
- wifi setup changed
|
|
|
|
# Time synchronisation
|
|
|
|
- name: Mask systemd-timesyncd
|
|
systemd:
|
|
name: systemd-timesyncd
|
|
state: stopped
|
|
enabled: no
|
|
masked: yes
|
|
become: yes
|
|
notify: etc changed
|
|
when: arch_based
|
|
|
|
- name: Install chrony
|
|
pacman:
|
|
name: chrony
|
|
state: present
|
|
when: arch_based
|
|
become: yes
|
|
|
|
- name: Configure chrony
|
|
copy:
|
|
src: chrony.conf
|
|
dest: /etc/chrony.conf
|
|
become: yes
|
|
notify:
|
|
- etc changed
|
|
- chrony reconfigured
|
|
# TODO More configuration, RTC configuration
|
|
|
|
- name: Enable chronyd
|
|
systemd:
|
|
name: chronyd
|
|
enabled: yes
|
|
become: yes
|
|
notify:
|
|
- etc changed
|
|
- chrony reconfigured
|
|
|
|
- name: Configure dhcpcd chrony hook
|
|
copy:
|
|
src: dhcpcd.exit-hook
|
|
dest: /etc/dhcpcd.exit-hook
|
|
become: yes
|
|
notify: etc changed
|
|
|
|
# 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
|