mirror of
https://codeberg.org/hyperreal/ansible-homelab
synced 2024-11-01 16:43:09 +01:00
61 lines
1.5 KiB
Markdown
61 lines
1.5 KiB
Markdown
|
# 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
|
||
|
lxc start debian-mail -- cloud-init --wait
|
||
|
```
|
||
|
|
||
|
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
|
||
|
```
|