Files
dotfiles/playbook.yml

414 lines
9.8 KiB
YAML
Raw Normal View History

2020-04-11 14:07:51 +02:00
- name: configure system
hosts: localhost
2018-02-05 20:09:05 +01:00
connection: local
become: false
tasks:
2018-08-17 19:44:31 +02:00
- name: read machine-specific variables
include_vars:
file: _machines/{{ ansible_hostname }}.yml
name: machine
tags:
- always
2018-02-08 21:45:02 +01:00
- set_fact:
distro: "{{ ansible_distribution|lower }}"
2018-08-17 19:44:31 +02:00
tags:
- always
2018-02-08 21:45:02 +01:00
2020-03-02 11:52:45 +01:00
- name: Check for valid distro
assert:
2020-12-08 22:00:44 +01:00
that: distro in ('fedora', 'ubuntu', 'archlinux')
2020-03-02 11:52:45 +01:00
2020-03-02 11:52:45 +01:00
- block:
- block:
- name: Update apt cache
apt:
update_cache: true
become: true
changed_when: false
2020-03-02 11:52:45 +01:00
- name: Upgrade system
apt:
upgrade: dist
become: true
- name: Remove unused packages
apt:
autoremove: true
become: true
- name: Clean apt cache
apt:
autoclean: true
become: true
when: distro == 'ubuntu'
2020-03-03 23:33:14 +01:00
2020-03-02 11:52:45 +01:00
- block:
2020-03-03 23:33:14 +01:00
- name: Update dnf cache
dnf:
update_cache: true
become: true
- name: Upgrade system
dnf:
name: '*'
state: latest
update_cache: false
2020-03-03 23:33:14 +01:00
become: true
- name: Remove unused packages
dnf:
autoremove: true
update_cache: false
2020-03-03 23:33:14 +01:00
become: true
2020-03-02 11:52:45 +01:00
when: distro == 'fedora'
2020-12-08 22:00:44 +01:00
- block:
- name: enable multilib repository
blockinfile:
path: /etc/pacman.conf
block: |
[multilib]
Include = /etc/pacman.d/mirrorlist
become: true
- name: Upgrade system
pacman:
upgrade: true
update_cache: true
become: true
changed_when: false
- name: install pacman-contrib for paccache
package:
name: pacman-contrib
state: installed
become: true
- name: Clean cache
command: paccache -rk2 -ruk0
become: true
2020-12-10 00:11:45 +01:00
changed_when: false
2020-12-08 22:00:44 +01:00
when: distro == 'archlinux'
2020-03-02 11:52:45 +01:00
tags: [update_system]
2018-02-11 12:03:54 +01:00
- name: install selinux specials on fedora
2019-04-14 11:54:29 +02:00
dnf:
2018-02-11 12:03:54 +01:00
state: installed
2019-04-14 11:54:29 +02:00
name:
2020-02-23 14:24:53 +01:00
- python3-libselinux
- policycoreutils-python-utils
2018-02-11 12:03:54 +01:00
become: true
when: distro == 'fedora'
2020-12-09 23:58:24 +01:00
- block:
- name: create build user on arch
user:
name: makepkg
home: /var/lib/makepkg
create_home: true
shell: /bin/bash
system: true
2020-12-09 23:58:24 +01:00
- name: build paru on arch
shell: |
set -o errexit
if pacman -Qi paru >/dev/null 2>&1; then
exit 100
fi
mkdir -p /tmp/paru-build
cd /tmp/paru-build
curl -L -O https://aur.archlinux.org/cgit/aur.git/snapshot/paru.tar.gz
tar xvf paru.tar.gz
cd paru
makepkg
args:
executable: /bin/bash
register: result
become: true # do not build as root!
become_user: makepkg
2020-12-09 23:58:24 +01:00
changed_when: result.rc != 100
failed_when: result.rc not in (0, 100)
- name: install paru
shell: |
set -o errexit
pacman --noconfirm -U /tmp/paru-build/paru/paru-*.pkg.tar.zst
rm -rf /tmp/paru-build
args:
executable: /bin/bash
become: true
when: result.rc != 100
when: distro == 'archlinux'
- block:
- name: load package list
include_vars:
file: packages.yml
- name: enable neovim ppa
apt_repository:
repo: 'ppa:neovim-ppa/stable'
update_cache: true
become: true
when: distro == 'ubuntu'
2018-02-05 20:09:05 +01:00
- set_fact:
defined_packages: "{{ packages|json_query('keys(list)') }}"
2018-02-05 20:09:05 +01:00
- set_fact:
distro_packages: "{{ packages|json_query('list.*.%s'|format(distro)) }}"
2018-02-05 20:09:05 +01:00
- name: check list
assert:
that: "defined_packages|length == distro_packages|length"
2018-02-05 20:09:05 +01:00
2020-10-05 22:03:05 +02:00
- set_fact:
defined_packages_remove: "{{ packages|json_query('keys(remove)') }}"
- set_fact:
distro_packages_remove: "{{ packages|json_query('remove.*.%s'|format(distro)) }}"
- name: check list
assert:
that: "defined_packages_remove|length == distro_packages_remove|length"
- name: install packages
package:
name: "{{ packages|json_query(query) }}"
state: installed
become: true
vars:
query: "{{ 'list.*.%s[]'|format(distro) }}"
2020-10-05 22:03:05 +02:00
- name: remove packages
package:
name: "{{ packages|json_query(query) }}"
state: absent
become: true
vars:
query: "{{ 'remove.*.%s[]'|format(distro) }}"
2020-12-09 00:15:54 +01:00
- name: install machine-specific packages
package:
name: "{{ machine.packages }}"
state: present
when: machine.packages is defined
become: true
tags: [packages]
2018-02-05 20:09:05 +01:00
2020-12-08 22:00:44 +01:00
- block:
- name: configure timesyncd on arch
copy:
owner: root
group: root
mode: "0644"
dest: /etc/systemd/timesyncd.conf
content: |
[Time]
NTP=0.arch.pool.ntp.org 1.arch.pool.ntp.org 2.arch.pool.ntp.org 3.arch.pool.ntp.org
FallbackNTP=0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org 3.pool.ntp.org
2020-12-09 19:36:41 +01:00
become: true
2020-12-09 21:43:57 +01:00
- name: install lz4
package:
name: lz4
state: installed
become: true
- name: use lz4 for mkinitcpio compression
lineinfile:
path: /etc/mkinitcpio.conf
regexp: '^#?COMPRESSION=.*$'
line: 'COMPRESSION="lz4"'
become: true
notify:
- rebuild initrd
2020-12-09 19:36:41 +01:00
when: distro == 'archlinux'
2020-12-08 22:00:44 +01:00
2019-05-20 21:29:26 +02:00
- set_fact:
disable_services:
- sshd
when: distro == 'fedora'
- set_fact:
disable_services:
- ssh
2020-12-08 22:00:44 +01:00
when: distro == 'ubuntu'
- set_fact:
disable_services:
- sshd
when: distro == 'archlinux'
2019-05-20 21:29:26 +02:00
2018-02-09 17:56:43 +01:00
- name: disable services
service:
state: stopped
enabled: false
name: "{{ item }}"
2019-05-20 21:29:26 +02:00
with_items: "{{ disable_services }}"
2018-02-09 17:56:43 +01:00
become: true
2020-12-08 23:41:35 +01:00
when: manage_services|default(true)|bool
2020-12-08 22:00:44 +01:00
- set_fact:
enable_services:
- NetworkManager
# does not work with fedora 31 due to the switch to cgroups v2:
# https://github.com/docker/cli/issues/2104
# https://bugzilla.redhat.com/show_bug.cgi?id=1746355#c1
# - docker
- libvirtd
when: distro == 'fedora'
- set_fact:
enable_services:
- NetworkManager
- docker
- libvirtd
when: distro == 'ubuntu'
- set_fact:
enable_services:
- NetworkManager
- docker
- libvirtd
- systemd-timesyncd
when: distro == 'archlinux'
2018-02-09 17:56:43 +01:00
- name: enable services
service:
state: started
enabled: true
name: "{{ item }}"
2020-12-08 22:00:44 +01:00
with_items: "{{ enable_services }}"
2020-02-23 14:56:14 +01:00
become: true
2020-12-08 23:41:35 +01:00
when: manage_services|default(true)|bool
2020-02-23 14:56:14 +01:00
2018-02-09 17:56:43 +01:00
- name: get systemd boot target
command: systemctl get-default
register: systemd_target
changed_when: false
2020-04-01 10:15:58 +02:00
check_mode: false
2018-02-09 17:56:43 +01:00
- set_fact:
default_target: multi-user.target
- name: set systemd boot target
command: systemctl set-default {{ default_target }}
when: systemd_target.stdout != default_target
become: true
- name: handle lid switch
lineinfile:
path: /etc/systemd/logind.conf
regexp: '^HandleLidSwitch='
line: 'HandleLidSwitch=ignore'
become: true
- name: handle power key
lineinfile:
path: /etc/systemd/logind.conf
regexp: '^HandlePowerKey='
line: 'HandlePowerKey=suspend'
become: true
2020-12-08 22:00:44 +01:00
- block:
- name: create sudonopw group
group:
name: sudonopw
system: true
- name: configure passwordless sudo
copy:
owner: root
group: root
mode: "0600"
dest: /etc/sudoers.d/sudonopw
content: |
%sudonopw ALL=(ALL) NOPASSWD: ALL
become: true
when: distro == 'archlinux'
- block:
- name: install AMDGPU packages
package:
name:
- mesa
- lib32-mesa
- xf86-video-amdgpu
- vulkan-radeon
- lib32-vulkan-radeon
- libva-mesa-driver
- lib32-libva-mesa-driver
- mesa-vdpau
- lib32-mesa-vdpau
state: installed
become: true
- name: set AMDGPU options
copy:
owner: root
group: root
mode: "0600"
dest: /etc/X11/xorg.conf.d/20-amdgpu.conf
content: |
Section "Device"
Identifier "AMD"
Driver "amdgpu"
Option "VariableRefresh" "true"
Option "TearFree" "true"
EndSection
2020-12-09 15:27:47 +01:00
become: true
2020-12-08 22:00:44 +01:00
when:
- distro == 'archlinux'
- machine.gpu is defined and machine.gpu == 'amd'
2019-11-14 10:40:16 +01:00
- name: create dotfiles group
group:
name: dotfiles
state: present
become: true
become_user: root
- name: create dotfiles directory
file:
state: directory
path: /var/lib/dotfiles
owner: nobody
group: dotfiles
2020-02-23 15:19:28 +01:00
mode: '0775' # group needs write access!
2019-11-14 10:40:16 +01:00
become: true
become_user: root
2019-11-14 09:16:55 +01:00
- set_fact:
users: "{{ machine.users }}"
2018-08-17 21:16:54 +02:00
tags:
2019-11-14 09:16:55 +01:00
- always
2018-08-17 21:16:54 +02:00
2019-11-14 09:16:55 +01:00
- include_tasks: user.yml
2018-08-17 21:16:54 +02:00
args:
2019-11-14 09:16:55 +01:00
apply:
become: true
become_user: "{{ user.name }}"
with_items: "{{ users }}"
loop_control:
loop_var: user
tags:
- always
handlers:
- name: rebuild initrd
command: mkinitcpio -P
become: true