notthebee / infra
- вторник, 28 декабря 2021 г. в 00:33:08
IaC for my Linux/Unix machines
An Ansible playbook that sets up an Ubuntu-based home media server/NAS with reasonable security, auto-updates, e-mail notifications for S.M.A.R.T. and Snapraid errors and dynamic DNS.
It assumes a fresh Ubuntu Server 20.04 install, access to a non-root user with sudo privileges and a public SSH key. This can be configured during the installation process.
The playbook is mostly being developed for personal use, so stuff is going to be constantly changing and breaking. Use at your own risk and don't expect any help in setting it up on your machine.
Install Ansible (macOS):
brew install ansible
Clone the repository:
git clone https://github.com/notthebee/infra
Create a host varialbe file and adjust the variables:
cd infra/ansible
mkdir -p host_vars/YOUR_HOSTNAME
vi host_vars/YOUR_HOSTNAME/vars.yml
Create a Keychain item for your Ansible Vault password (on macOS):
security add-generic-password \
-a YOUR_USERNAME \
-s ansible-vault-password \
-w
The pass.sh
script will extract the Ansible Vault password from your Keychain automatically each time Ansible requests it.
Create an encrypted secret.yml
file and adjust the variables:
touch host_vars/YOUR_HOSTNAME/secret.yml
ansible-vault encrypt host_vars/YOUR_HOSTNAME/secret.yml
ansible-vault edit host_vars/YOUR_HOSTNAME/secret.yml
Add your custom inventory file to hosts
:
cp hosts_example hosts
vi hosts
Install the dependencies:
ansible-galaxy install -r requirements.yml
Finally, run the playbook:
ansible-playbook run.yml -l your-host-here -K
The "-K" parameter is only necessary for the first run, since the playbook configures passwordless sudo for the main login user
For consecutive runs, if you only want to update the Docker containers, you can run the playbook like this:
ansible-playbook run.yml --tags="port,containers"