Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# pi-ansible-automation
A set of roles (mostly) tested & optimized towards raspberry PI running Raspberry PI OS (Bookworm debian arm64)
A set of roles (mostly) tested & optimized towards raspberry PI running Raspberry PI OS (Trixie Debian arm64)

## avahi-discoverable
enables avahi hostname mDNS broadcasting so you can reach host on hostname.local


**kodi**
installs & configures kodi.
| Variable name | Example | Mandatory |
| -------------------- |:-------------:| :----------:|
| kodi_remote_password:| somesecret | yes |

## pihole
un-attended install of pihole for DNS based ad-blocking
Expand Down Expand Up @@ -75,6 +78,8 @@ DNS over TLS using Cloudflares clourflared for DNS proxying.
| cloudflared_release_ver: | | yes |
| doh_dns_1: | 1.1.1.1 | yes |
| doh_dns_2: | 1.0.0.1 | yes |
| dns_hosts | dns_hosts: -
facebook.com: 0.0.0.0 | no |

## single-nic-firewall
Sets up a single nic NAT:ing Firewall with a DHCP server using VLANs & nftables for firewalling.
Expand Down
5 changes: 5 additions & 0 deletions roles/autottylogin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## autottylogin
un-attended configuration of a linux host to automatically log in on the console

By default the linux sound system (pipewire or pulseaudio) is run in a per-user basis. The audio process is stared only when a user is logged in.
So for a headless setup you need something to be logged in for audio to work. There is a (unsupported) global mode but it's not recommended so this is the workaround
18 changes: 16 additions & 2 deletions roles/autottylogin/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
createhome: true
groups: video,input

- name: Create folder required for getty
ansible.builtin.file:
path: /etc/systemd/system/getty.target.wants/
state: directory
owner: root
group: root
mode: '0700'

- name: Enable autologin
ansible.builtin.file:
src: /lib/systemd/system/getty@.service
Expand All @@ -30,12 +38,18 @@
group: root
mode: '0644'

- name: Install ACL package (Required for ansible_become on media user in othe roles)
- name: Install ACL package (Required for ansible_become on media user in other roles)
ansible.builtin.apt:
name: acl
state: present
install_recommends: false

- name: Install pipewire
ansible.builtin.apt:
name: pipewire
state: present
install_recommends: false

- name: Create .ssh folder
ansible.builtin.file:
path: /home/media/.ssh
Expand All @@ -47,7 +61,7 @@
# This task is required because it's not possible to manage a systemd USER service
# with ansible if you are not doing it while being that user
# by enabling login with SSH for the media user we can handle enabling starting services as that user
# in other tasks (all audio related for enableing audio related user services
# in other tasks (all audio related for enabling audio related user services
- name: Deploy current users public SSH key for media user
ansible.builtin.copy:
remote_src: true
Expand Down
65 changes: 39 additions & 26 deletions roles/kodi/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
---

- name: Enable auto login on tty for media user (required for pulseaudio to work)
- name: Enable auto login on tty for media user (pipewire requires a logged in user for audio to work)
ansible.builtin.include_role:
name: autottylogin

- name: Install packages
ansible.builtin.apt:
name: "{{ kodi_packages }}"
install_recommends: false
update_cache: true

- name: Create user systemd folder
Expand Down Expand Up @@ -59,30 +60,42 @@
notify: Restart kodi
tags: sources

- name: Register Raspberry PI model info
ansible.builtin.shell: set -o pipefail && /usr/bin/cat /proc/cpuinfo |grep Model
args:
executable: /bin/bash
register: kodi_cpu_model
check_mode: false
changed_when: false
- name: Configure sane kodi GUI defaults
ansible.builtin.replace:
path: /home/media/.kodi/userdata/guisettings.xml
regexp: "{{ item.key }}"
replace: "{{ item.value }}"
loop:
# Set country for proper time
- key: '<setting id="locale\.country" default="true">USA\ \(12h\)</setting>'
value: '<setting id="locale.country">Central Europe</setting>'

- name: Tweak gpu_mem for non Pi4 for video to work
ansible.builtin.lineinfile:
path: /boot/config.txt
line: "gpu_mem=256"
create: true
owner: root
group: root
mode: '644'
when: kodi_cpu_model.stdout.find("Pi 4") == -1
# Set country for proper time
- key: '<setting id="locale.timezonecountry" default="true"\ />'
value: '<setting id="locale.timezonecountry" default="true">Sweden</setting>'

- name: Tweak gpu_mem for Pi4 to make H265 HW decoding work
ansible.builtin.lineinfile:
path: /boot/config.txt
line: "dtoverlay=rpivid-v4l2"
create: true
owner: root
group: root
mode: '644'
when: kodi_cpu_model.stdout.find("Pi 4") != -1
# Set Kodi resolution to 1080p
- key: '<setting\ id="videoscreen\.resolution" default="true">16</setting>'
value: <setting id="videoscreen.resolution">18</setting>

# Set Kodi resolution to 1080p
- key: '<setting id="videoscreen.screenmode"\ default="true">DESKTOP</setting>'
value: '<setting id="videoscreen.screenmode">0192001080060.00000pstd</setting>'

# Enable airplay
- key: '<setting\ id="services\.airplay"\ default="true">false</setting>'
value: '<setting id="services.airplay">true</setting>'

# Enable remote control
- key: '<setting\ id="services\.webserver"\ default="true">false</setting>'
value: '<setting id="services.webserver">true</setting>'

# Set password for remote control
- key: '<setting\ id="services\.webserverpassword"\ default="true"\ />'
value: '<setting id="services.webserverpassword">{{ kodi_remote_password }}</setting>'

# Allow using third party kodi plugin repositories
- key: '<setting\ id="addons\.unknownsources"\ default="true">false</setting>'
value: <setting id="addons.unknownsources">true</setting>
notify: Restart kodi
tags: guisettings
6 changes: 4 additions & 2 deletions roles/kodi/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ kodi_packages:
- acl
- ca-certificates
- cec-utils
- kodi
- kodi-inputstream-adaptive
- kodi-repository
- kodi-visualization-spectrum
- kodi-vfs-rar
- kodi21
- kodi21-inputstream-adaptive
- mesa-utils
- pulseaudio
- samba-common-bin