From 8e7d6db56ba2f513674565454ce51ae31438bc84 Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Sat, 16 Mar 2024 10:36:59 +0100 Subject: [PATCH] Remove template timestamps & move tasks to handlers These changes will prevent services from being restarted without any changes whenever no changes have been made --- handlers.yml | 33 ++++++++++++++++++++ tasks/network.yml | 30 +++++------------- tasks/pipewire.yml | 13 ++------ templates/desktop/network/enp.network.j2 | 2 -- templates/desktop/network/wg0.netdev.j2 | 2 -- templates/desktop/network/wg0.network.j2 | 2 -- templates/desktop/nftables.j2 | 2 -- templates/desktop/pipewire-pulse.j2 | 2 -- templates/desktop/syncthing.j2 | 2 -- templates/gitconfig.j2 | 3 -- templates/laptop/network/wg0.netdev.j2 | 2 -- templates/laptop/network/wg0.network.j2 | 2 -- templates/laptop/network/wireless.network.j2 | 2 -- templates/laptop/nftables.j2 | 2 -- templates/laptop/nouveau-blacklist.j2 | 2 -- templates/laptop/pipewire-pulse.j2 | 2 -- templates/laptop/powertop.j2 | 2 -- templates/laptop/syncthing.j2 | 2 -- templates/laptop/udev.j2 | 2 -- templates/mpv/config.j2 | 4 +-- templates/mpv/input.j2 | 2 -- templates/pacman.j2 | 10 ++---- templates/reflector.j2 | 2 -- templates/ssh-agent.j2 | 2 -- templates/timer/daily_target.j2 | 2 -- templates/timer/daily_timer.j2 | 3 -- templates/timer/weekly_target.j2 | 2 -- templates/timer/weekly_timer.j2 | 3 -- templates/tmux.j2 | 2 -- 29 files changed, 46 insertions(+), 95 deletions(-) diff --git a/handlers.yml b/handlers.yml index e613358..dccba92 100644 --- a/handlers.yml +++ b/handlers.yml @@ -36,3 +36,36 @@ state: restarted enabled: true daemon-reload: true + +- name: restart systemd-networkd + become: true + systemd: + name: systemd-networkd + state: restarted + enabled: true + +- name: start systemd-resolved service + become: true + systemd: + name: systemd-resolved + state: started + enabled: true + +- name: start iwd service + become: true + systemd: + name: iwd + state: started + enabled: true + when: platform == "laptop" + +- name: restart pipewire-pulse + systemd: + name: '{{ item.name }}' + state: restarted + enabled: '{{ item.enabled }}' + scope: user + daemon-reload: true + loop: + - { name: 'pipewire-pulse.socket', enabled: true } + - { name: 'pipewire-pulse.service', enabled: false } diff --git a/tasks/network.yml b/tasks/network.yml index 1163846..9cda432 100644 --- a/tasks/network.yml +++ b/tasks/network.yml @@ -73,6 +73,10 @@ loop: - '/etc/systemd/network/30-vmbr0.network' - '/etc/systemd/network/30-vmbr0.netdev' + + notify: + - restart systemd-networkd + - restart systemd-resolved when: platform == "desktop" - block: @@ -107,28 +111,10 @@ - '/etc/systemd/network/30-vmbr0.network' - '/etc/systemd/network/30-vmbr0.netdev' - when: platform == "laptop" - -- name: restart systemd-networkd - become: true - systemd: - name: systemd-networkd - state: restarted - enabled: true - -- name: start systemd-resolved service - become: true - systemd: - name: systemd-resolved - state: started - enabled: true - -- name: start iwd service - become: true - systemd: - name: iwd - state: started - enabled: true + notify: + - restart systemd-networkd + - restart systemd-resolved + - restart iwd when: platform == "laptop" - name: copy firewall template diff --git a/tasks/pipewire.yml b/tasks/pipewire.yml index 2efa001..5a5b905 100644 --- a/tasks/pipewire.yml +++ b/tasks/pipewire.yml @@ -17,6 +17,7 @@ template: src: 'templates/{{ platform }}/pipewire-pulse.j2' dest: '{{ xdg_config_dir }}/pipewire/pipewire-pulse.conf' + notify: restart pipewire-pulse - name: gather the package facts package_facts: @@ -29,6 +30,7 @@ state: present extra_args: --noconfirm --ask=4 when: "'pipewire-media-session' in ansible_facts.packages or not 'wireplumber' in ansible_facts.packages" + notify: restart pipewire-pulse - name: start pipewire socket systemd: @@ -36,14 +38,3 @@ state: started enabled: true scope: user - -- name: restart pipewire-pulse - systemd: - name: '{{ item.name }}' - state: restarted - enabled: '{{ item.enabled }}' - scope: user - daemon-reload: true - loop: - - { name: 'pipewire-pulse.socket', enabled: true } - - { name: 'pipewire-pulse.service', enabled: false } diff --git a/templates/desktop/network/enp.network.j2 b/templates/desktop/network/enp.network.j2 index 3329399..252cbe9 100644 --- a/templates/desktop/network/enp.network.j2 +++ b/templates/desktop/network/enp.network.j2 @@ -1,5 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} - [Match] Name=enp* diff --git a/templates/desktop/network/wg0.netdev.j2 b/templates/desktop/network/wg0.netdev.j2 index de4e81e..2397e90 100644 --- a/templates/desktop/network/wg0.netdev.j2 +++ b/templates/desktop/network/wg0.netdev.j2 @@ -1,5 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} - [NetDev] Name={{ vpn_interface }} Kind=wireguard diff --git a/templates/desktop/network/wg0.network.j2 b/templates/desktop/network/wg0.network.j2 index 81fbe8a..4a5a6e2 100644 --- a/templates/desktop/network/wg0.network.j2 +++ b/templates/desktop/network/wg0.network.j2 @@ -1,5 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} - [Match] Name={{ vpn_interface }} diff --git a/templates/desktop/nftables.j2 b/templates/desktop/nftables.j2 index cdea740..2f37138 100644 --- a/templates/desktop/nftables.j2 +++ b/templates/desktop/nftables.j2 @@ -1,5 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} -# #!/usr/bin/nft -f # vim:set ts=2 sw=2 et: diff --git a/templates/desktop/pipewire-pulse.j2 b/templates/desktop/pipewire-pulse.j2 index bf26dab..56d29e3 100644 --- a/templates/desktop/pipewire-pulse.j2 +++ b/templates/desktop/pipewire-pulse.j2 @@ -1,5 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} -# # PulseAudio config file for PipeWire version "0.3.48" # # # Copy and edit this file in /etc/pipewire for system-wide changes diff --git a/templates/desktop/syncthing.j2 b/templates/desktop/syncthing.j2 index d9e59f9..f4f290f 100644 --- a/templates/desktop/syncthing.j2 +++ b/templates/desktop/syncthing.j2 @@ -1,5 +1,3 @@ - - basic diff --git a/templates/gitconfig.j2 b/templates/gitconfig.j2 index 4b97063..3c1e9d9 100644 --- a/templates/gitconfig.j2 +++ b/templates/gitconfig.j2 @@ -1,6 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} -# - [user] email = sonny871@hotmail.com name = Sonny Bakker diff --git a/templates/laptop/network/wg0.netdev.j2 b/templates/laptop/network/wg0.netdev.j2 index de4e81e..2397e90 100644 --- a/templates/laptop/network/wg0.netdev.j2 +++ b/templates/laptop/network/wg0.netdev.j2 @@ -1,5 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} - [NetDev] Name={{ vpn_interface }} Kind=wireguard diff --git a/templates/laptop/network/wg0.network.j2 b/templates/laptop/network/wg0.network.j2 index 81fbe8a..4a5a6e2 100644 --- a/templates/laptop/network/wg0.network.j2 +++ b/templates/laptop/network/wg0.network.j2 @@ -1,5 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} - [Match] Name={{ vpn_interface }} diff --git a/templates/laptop/network/wireless.network.j2 b/templates/laptop/network/wireless.network.j2 index 894c5db..3c23fc2 100644 --- a/templates/laptop/network/wireless.network.j2 +++ b/templates/laptop/network/wireless.network.j2 @@ -1,5 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} - [Match] Name=wlan0 diff --git a/templates/laptop/nftables.j2 b/templates/laptop/nftables.j2 index 8c01f2a..b54a534 100644 --- a/templates/laptop/nftables.j2 +++ b/templates/laptop/nftables.j2 @@ -1,5 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} -# #!/usr/bin/nft -f # vim:set ts=2 sw=2 et: diff --git a/templates/laptop/nouveau-blacklist.j2 b/templates/laptop/nouveau-blacklist.j2 index 0a4edd5..c9b9bfc 100644 --- a/templates/laptop/nouveau-blacklist.j2 +++ b/templates/laptop/nouveau-blacklist.j2 @@ -1,4 +1,2 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} - blacklist nouveau options nouveau modeset=0 diff --git a/templates/laptop/pipewire-pulse.j2 b/templates/laptop/pipewire-pulse.j2 index bf26dab..56d29e3 100644 --- a/templates/laptop/pipewire-pulse.j2 +++ b/templates/laptop/pipewire-pulse.j2 @@ -1,5 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} -# # PulseAudio config file for PipeWire version "0.3.48" # # # Copy and edit this file in /etc/pipewire for system-wide changes diff --git a/templates/laptop/powertop.j2 b/templates/laptop/powertop.j2 index 6b15cc7..d30f4ce 100644 --- a/templates/laptop/powertop.j2 +++ b/templates/laptop/powertop.j2 @@ -1,5 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} - [Unit] Description=Powertop tunings diff --git a/templates/laptop/syncthing.j2 b/templates/laptop/syncthing.j2 index e653f67..4112f18 100644 --- a/templates/laptop/syncthing.j2 +++ b/templates/laptop/syncthing.j2 @@ -1,5 +1,3 @@ - - basic diff --git a/templates/laptop/udev.j2 b/templates/laptop/udev.j2 index 8283502..e9a40ab 100644 --- a/templates/laptop/udev.j2 +++ b/templates/laptop/udev.j2 @@ -1,4 +1,2 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} - # Remove NVIDIA VGA/3D controller devices ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x03[0-9]*", ATTR{power/control}="auto", ATTR{remove}="1" diff --git a/templates/mpv/config.j2 b/templates/mpv/config.j2 index c8ad07d..332f251 100644 --- a/templates/mpv/config.j2 +++ b/templates/mpv/config.j2 @@ -1,6 +1,4 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} - -volume=100 +olume=100 sub-auto=fuzzy gpu-api=opengl vo=gpu diff --git a/templates/mpv/input.j2 b/templates/mpv/input.j2 index b63757d..b2cfeb4 100644 --- a/templates/mpv/input.j2 +++ b/templates/mpv/input.j2 @@ -1,5 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} -# ## Seek units are in seconds, but note that these are limited by keyframes RIGHT seek 5 LEFT seek -5 diff --git a/templates/pacman.j2 b/templates/pacman.j2 index becd0db..a77bbeb 100644 --- a/templates/pacman.j2 +++ b/templates/pacman.j2 @@ -1,6 +1,3 @@ -# TODO: update testing libraries according to new config -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} -# # /etc/pacman.conf # # Add environment specific settings in /etc/pacman.d/extra.conf @@ -82,13 +79,10 @@ LocalFileSigLevel = Optional [core] Include = /etc/pacman.d/mirrorlist -[extra] -Include = /etc/pacman.d/mirrorlist - -#[community-testing] +#[extra-testing] #Include = /etc/pacman.d/mirrorlist -[community] +[extra] Include = /etc/pacman.d/mirrorlist # If you want to run 32 bit applications on your x86_64 system, diff --git a/templates/reflector.j2 b/templates/reflector.j2 index fbd1a42..97b701b 100644 --- a/templates/reflector.j2 +++ b/templates/reflector.j2 @@ -1,5 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} -# # Reflector configuration file for the systemd service. # # Empty lines and lines beginning with "#" are ignored. All other lines should diff --git a/templates/ssh-agent.j2 b/templates/ssh-agent.j2 index 67fdbea..9428410 100644 --- a/templates/ssh-agent.j2 +++ b/templates/ssh-agent.j2 @@ -1,5 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} - [Unit] Description=SSH key agent diff --git a/templates/timer/daily_target.j2 b/templates/timer/daily_target.j2 index bf4d594..c1eb670 100644 --- a/templates/timer/daily_target.j2 +++ b/templates/timer/daily_target.j2 @@ -1,5 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} -# # Add the following to your service unit to make use of this target: # Wants=daily.target # diff --git a/templates/timer/daily_timer.j2 b/templates/timer/daily_timer.j2 index cdc47f0..08ebc1a 100644 --- a/templates/timer/daily_timer.j2 +++ b/templates/timer/daily_timer.j2 @@ -1,6 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} -# - [Unit] Description=Timer which runs all services on a daily basis inside the daily.target.wants directory diff --git a/templates/timer/weekly_target.j2 b/templates/timer/weekly_target.j2 index 7e944cb..606a319 100644 --- a/templates/timer/weekly_target.j2 +++ b/templates/timer/weekly_target.j2 @@ -1,5 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} -# # Add the following to your service unit to make use of this target: # Wants=weekly.target # diff --git a/templates/timer/weekly_timer.j2 b/templates/timer/weekly_timer.j2 index e4c33f4..2a5ad77 100644 --- a/templates/timer/weekly_timer.j2 +++ b/templates/timer/weekly_timer.j2 @@ -1,6 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} -# - [Unit] Description=Timer which runs all services on a weekly basis inside the weekly.target.wants directory diff --git a/templates/tmux.j2 b/templates/tmux.j2 index 8fa1473..0b1f6dd 100644 --- a/templates/tmux.j2 +++ b/templates/tmux.j2 @@ -1,5 +1,3 @@ -# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }} - [Unit] Description=Tmux startup script