This repository contains Ansible playbooks to set up a personal MacBook and home server. This README provides instructions on how to customize variables and run the playbooks.
Install Ansible on your local machine.
python -m pip install ansible
Before running the playbook, you need to set the desired variables in group_vars/*
files.
Also be sure to set up inventory.ini
with the correct IP addresses of your hosts.
Install command line tools to get git
xcode-select –-install
Create env and install ansible
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
Update the roles
ansible-galaxy install -r requirements.yml --force
To run the playbooks, execute the following command:
ansible-playbook playbook_macbook.yml --ask-become-pass
ansible-playbook playbook_work_macbook.yml --ask-become-pass
ansible-playbook playbook_homelab.yml
ansible-playbook playbook_vps.yml
- create vault password file .vault_pass.txt
- to encrypt smth ansible-vault encrypt_string --stdin-name mas_email
- to decrypt ansible-vault decrypt_string --stdin-name mas_email
- to run ansible-playbook -i inventory.ini playbook_macbook.yml
- to run ansible-playbook -i inventory.ini playbook_vps.yml
To lint run yamllint .
and ansible-lint
Create duckdns [DOMAIN] and [TOKEN]
Connect disk to the raspberry pi and get uuid (PARTUUID)
sudo blkid
update vars/homelab.yml
- Install raspbian lite on raspberry pi
Easy way: use raspberry pi imager
Fill wi-fi credentials and enable ssh with your ssh key - Create ssh config for the homelab with key and
homelab
announced name - Run
ansible-playbook -i inventory.ini playbook_homelab.yml
to setup homelab
- Connect raspberry pi to the power (auto network connection)
- Fix ip address in router settings
Home Network -> Network -> Network Connections -> Edit homelab -- "Always assign this network device the same IPv4 address" - Announce homelab as upstream dns server in router settings
Internet -> Account Information -> DNS Server -> Use other DNSv4/DNSv6 Servers
- Fill both fields with raspberry pi ip address
- Checkbox fallback to public dns
- Forward vpn subnet through homelab
Home Network -> Network -> Network Settings -> IPv4 Addresses -> Network Settings -> IPv4 Routes -> New IPv4 Route
(same as in vars/all.yml)IPv4 Network: 10.1.0.0 Subnet Mask: 255.255.255.0 (/24) Gateway: [homelab fixed ip] Ipv4 route active: checked
- Forward ports to homelab
Internet -> Permit Access -> Port Sharing -> New Port Sharing Rule
Device: homelab
New Sharing -> Port SharingApplication: Custom Service Name: Wireguard Protocol: UPD Port: 51820
Create duckdns [DOMAIN] and [TOKEN]
ansible-playbook -i inventory.ini playbook_router.yml --tags=generate
- Setup DynDNS to update on the router
Internet -> Permit Access -> DynDNS
Update URL: https://www.duckdns.org/update?domains=[DOMAIN]&token=[TOKEN]&ip=<ipaddr>&ipv6=<ip6addr> Domain Name: [DOMAIN].duckdns.org Username: none Password: [TOKEN]
- Enable Wireguard on the router
Internet -> Permit Access -> VPN (WireGuard) -> Enable WireGuard -> Add connectionLoad config fromConnect networks or establish special connections already been set up: yes Name: wg0
.tmp/router-wg0.conf