kodi media services basic setup

This commit is contained in:
2024-04-21 01:04:17 +12:00
parent cb4abe5722
commit 3d9241b475
14 changed files with 155 additions and 24 deletions

View File

@ -0,0 +1,16 @@
sshd:
config_path: default
auth:
pubkey: 'yes'
password: 'no'
empty: 'no'
listen:
port: '22'
family: any # 'any', 'inet' or 'inet6'
ipv4:
- '0.0.0.0'
ipv6:
- '::'
forwarding:
agent: 'no'
x11: 'no'

View File

@ -0,0 +1,6 @@
---
- name: Restart sshd
ansible.builtin.service:
name: sshd.service
state: restarted

View File

@ -0,0 +1,14 @@
---
- name: Template out sshd_config
ansible.builtin.template:
src: sshd_config.j2
dest: /etc/ssh/sshd_config
owner: root
group: root
mode: '0644'
notify:
- Restart sshd
- name: Flush handlers for immediate shhd restart
ansible.builtin.meta: flush_handlers

View File

@ -0,0 +1,55 @@
---
- name: Ensure ssh config dir exists
delegate_to: localhost
become: false
ansible.builtin.file:
path: "{{ lookup('env', 'HOME') }}/.ssh/conf.d/{{ sshd.config_path }}"
state: directory
owner: "{{ lookup('env', 'USER') }}"
group: "{{ lookup('env', 'USER') }}"
mode: '0700'
- name: Generate local SSH key pair
delegate_to: localhost
become: false
community.crypto.openssh_keypair:
backend: opensshbin
comment: "{{ ansible_user }}@{{ static_fqdn }}"
mode: '0600'
passphrase: "{{ ssh_keygen_passphrase }}"
path: "{{ lookup('env', 'HOME') }}/.ssh/conf.d/{{ sshd.config_path }}/{{ static_fqdn }}"
regenerate: full_idempotence
size: 521
state: present
type: ecdsa
register: ssh_keygen
- name: Copy SSH pubkey to target
ansible.posix.authorized_key:
key: "{{ ssh_keygen.public_key }}"
user: "{{ ansible_user }}"
state: present
- name: Add local ssh client config
delegate_to: localhost
become: false
community.general.ssh_config:
host: "{{ sshd.nickname | default(omit) }} {{ static_fqdn }}"
hostname: "{{ static_fqdn }}"
identity_file: "{{ ssh_keygen.filename }}"
port: "{{ sshd.listen.port | default('22') }}"
remote_user: "{{ ansible_user }}"
ssh_config_file: "{{ lookup('env', 'HOME') }}/.ssh/conf.d/{{ sshd.config_path }}/{{ static_fqdn }}.conf"
state: present
- name: Include generated ssh config in default config file
delegate_to: localhost
become: false
ansible.builtin.lineinfile:
path: "{{ lookup('env', 'HOME') }}/.ssh/config"
line: "Include {{ lookup('env', 'HOME') }}/.ssh/conf.d/{{ sshd.config_path }}/{{ static_fqdn }}.conf"
mode: '0600'
state: present
create: true
insertafter: ^Include\s.*$

View File

@ -0,0 +1,120 @@
Port {{ sshd.listen.port | default('22') }}
AddressFamily {{ sshd.listen.family | default('any') }}
{% if (sshd.listen.family is defined and sshd.listen.family == 'inet') or (sshd.listen.family is defined and sshd.listen.family == 'any') -%}
{% if sshd.listen.ipv4 is defined -%}
{% for address in sshd.listen.ipv4 -%}
ListenAddress {{ address }}
{% endfor -%}
{% else -%}
ListenAddress 0.0.0.0
{% endif -%}
{% endif -%}
{% if (sshd.listen.family is defined and sshd.listen.family == 'inet6') or (sshd.listen.family is defined and sshd.listen.family == 'any') -%}
{% if sshd.listen.ipv6 is defined -%}
{% for address in sshd.listen.ipv6 -%}
ListenAddress {{ address }}
{% endfor -%}
{% else -%}
ListenAddress ::
{% endif -%}
{% endif -%}
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
PubkeyAuthentication {{ sshd.auth.pubkey | default('yes') }}
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys
#AuthorizedPrincipalsFile none
#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication {{ sshd.auth.password | default('yes') }}
PermitEmptyPasswords {{ sshd.auth.empty | default('no') }}
# Change to no to disable s/key passwords
KbdInteractiveAuthentication no
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the KbdInteractiveAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via KbdInteractiveAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
UsePAM yes
AllowAgentForwarding {{ sshd.forwarding.agent | default('no') }}
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding {{ sshd.forwarding.x11 | default('no') }}
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no # pam does that
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
# Banner Connected to {{ ansible_fqdn | default('host.') }}
# override default of no subsystems
Subsystem sftp /usr/lib/ssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server