2023-06-01 19:02:20 +02:00
# ansible-homelab
I use these roles to automate the setup of my LXC homelab. They are highly tailored to my use-case and would require substantial review and editing for anyone else to use them.
## Example
Initialize an instance:
``` shell
lxc init images:debian/12/cloud debian-mail --storage lxd-pool
```
Configure the instance with cloud-init:
```shell
lxc config set debian-mail cloud-init.user-data - < < - EOF
#cloud-config
users:
- name: debian
ssh_authorized_keys:
- ssh-ed25519 ...
sudo: 'ALL=(ALL) NOPASSWD: ALL'
lock_passwd: false
passwd: $6$rounds=4096$aVIiqgNjZRRxZXRa$rshJoBQ4gedhAmIT3kSvwxyw6AmD4ZYQFHrUMmgnH70F98yLrt7w3bO9bOy9tWHRK0X3TlC/dUnzDBla3Ti6H
packages:
- python3-dev
- ssh
EOF
```
The hashed password can be generated with the `mkpasswd` command, which, for some reason, is provided by the *whois* package on Ubuntu-based systems:
```shell
sudo apt install -y whois
mkpasswd --method=SHA-512 --rounds=4096
```
Copy and paste the result as the value of the passwd key in the cloud-config.
Start the instance, then check the cloud-init status:
```shell
2023-06-01 19:04:27 +02:00
lxc start debian-mail
lxc exec debian-mail -- cloud-init status --wait
2023-06-01 19:02:20 +02:00
```
Once that's done, you should be able to ssh directly to the debian user, and Ansible will be ready to run.
Add instance IP address to `hosts.ini` :
``` ini
[homelab]
10.227.115.42
```
Run the `setup.yml` playbook for all roles, or choose specific roles with `--tags` :
``` shell
ansible-playbook -i hosts.ini setup.yml -u debian -b
ansible-playbook -i hosts.ini setup.yml --tags debian-mail -u debian -b
```