Initial Ansible automation for hobbs.farm infrastructure
Complete IaC covering: - 14 roles: common, docker, traefik, vaultwarden, monitoring, media, matrix, home_assistant, frigate, adguard, gitea, semaphore, openclaw, security, backup - Inventory for all hosts (Peggy, Bart, Yoda, NAS, Firewalla) - Stack playbooks: core-infrastructure, monitoring, media, communication, automation, smarthome, security-hardening - Maintenance playbooks: update-containers, backup, health-check - Production Docker Compose templates with Traefik labels - Security hardening (sysctl, auditd, UFW, fail2ban) - Automated backups with retention policy
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
---
|
||||
common_packages:
|
||||
- htop
|
||||
- iotop
|
||||
- curl
|
||||
- wget
|
||||
- git
|
||||
- jq
|
||||
- unzip
|
||||
- net-tools
|
||||
- ncdu
|
||||
- tmux
|
||||
- rsync
|
||||
- lsof
|
||||
- vim
|
||||
- ufw
|
||||
- fail2ban
|
||||
|
||||
common_timezone: America/Chicago
|
||||
common_hostname: "{{ hostname | default(inventory_hostname) }}"
|
||||
sshd_port: 22
|
||||
sshd_permit_root: "no"
|
||||
sshd_password_auth: "no"
|
||||
sshd_pubkey_auth: "yes"
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- name: Restart sshd
|
||||
ansible.builtin.systemd:
|
||||
name: sshd
|
||||
state: restarted
|
||||
@@ -0,0 +1,98 @@
|
||||
---
|
||||
- name: Set hostname
|
||||
ansible.builtin.hostname:
|
||||
name: "{{ common_hostname }}"
|
||||
tags: [common, hostname]
|
||||
|
||||
- name: Set timezone
|
||||
community.general.timezone:
|
||||
name: "{{ common_timezone }}"
|
||||
tags: [common, timezone]
|
||||
|
||||
- name: Update apt cache
|
||||
ansible.builtin.apt:
|
||||
update_cache: true
|
||||
cache_valid_time: 3600
|
||||
tags: [common, packages]
|
||||
|
||||
- name: Install common packages
|
||||
ansible.builtin.apt:
|
||||
name: "{{ common_packages }}"
|
||||
state: present
|
||||
tags: [common, packages]
|
||||
|
||||
- name: Upgrade all packages
|
||||
ansible.builtin.apt:
|
||||
upgrade: safe
|
||||
tags: [common, packages, upgrade]
|
||||
when: apt_upgrade | default(false) | bool
|
||||
|
||||
- name: Configure SSH daemon
|
||||
ansible.builtin.template:
|
||||
src: sshd_config.j2
|
||||
dest: /etc/ssh/sshd_config
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
validate: "sshd -t -f %s"
|
||||
notify: Restart sshd
|
||||
tags: [common, ssh]
|
||||
|
||||
- name: Ensure SSH is running
|
||||
ansible.builtin.systemd:
|
||||
name: sshd
|
||||
state: started
|
||||
enabled: true
|
||||
tags: [common, ssh]
|
||||
|
||||
- name: Configure UFW defaults
|
||||
community.general.ufw:
|
||||
direction: incoming
|
||||
policy: deny
|
||||
tags: [common, firewall]
|
||||
|
||||
- name: Allow SSH through UFW
|
||||
community.general.ufw:
|
||||
rule: allow
|
||||
port: "{{ sshd_port }}"
|
||||
proto: tcp
|
||||
tags: [common, firewall]
|
||||
|
||||
- name: Allow traffic from local network
|
||||
community.general.ufw:
|
||||
rule: allow
|
||||
src: 192.168.86.0/24
|
||||
tags: [common, firewall]
|
||||
|
||||
- name: Enable UFW
|
||||
community.general.ufw:
|
||||
state: enabled
|
||||
tags: [common, firewall]
|
||||
|
||||
- name: Configure fail2ban
|
||||
ansible.builtin.systemd:
|
||||
name: fail2ban
|
||||
state: started
|
||||
enabled: true
|
||||
tags: [common, security]
|
||||
|
||||
- name: Set vm.swappiness
|
||||
ansible.posix.sysctl:
|
||||
name: vm.swappiness
|
||||
value: "10"
|
||||
state: present
|
||||
reload: true
|
||||
tags: [common, sysctl]
|
||||
|
||||
- name: Configure NTP
|
||||
ansible.builtin.apt:
|
||||
name: chrony
|
||||
state: present
|
||||
tags: [common, ntp]
|
||||
|
||||
- name: Start chrony
|
||||
ansible.builtin.systemd:
|
||||
name: chrony
|
||||
state: started
|
||||
enabled: true
|
||||
tags: [common, ntp]
|
||||
@@ -0,0 +1,26 @@
|
||||
# Managed by Ansible - do not edit manually
|
||||
Port {{ sshd_port }}
|
||||
AddressFamily any
|
||||
ListenAddress 0.0.0.0
|
||||
ListenAddress ::
|
||||
|
||||
HostKey /etc/ssh/ssh_host_rsa_key
|
||||
HostKey /etc/ssh/ssh_host_ecdsa_key
|
||||
HostKey /etc/ssh/ssh_host_ed25519_key
|
||||
|
||||
PermitRootLogin {{ sshd_permit_root }}
|
||||
PubkeyAuthentication {{ sshd_pubkey_auth }}
|
||||
PasswordAuthentication {{ sshd_password_auth }}
|
||||
ChallengeResponseAuthentication no
|
||||
UsePAM yes
|
||||
|
||||
X11Forwarding no
|
||||
PrintMotd no
|
||||
AcceptEnv LANG LC_*
|
||||
|
||||
MaxAuthTries 3
|
||||
MaxSessions 10
|
||||
ClientAliveInterval 300
|
||||
ClientAliveCountMax 2
|
||||
|
||||
Subsystem sftp /usr/lib/openssh/sftp-server
|
||||
Reference in New Issue
Block a user