Go to file
2023-06-04 11:44:34 -05:00
cloud-init Remove runcmd 2023-06-04 11:44:34 -05:00
roles Add cloud-init configs 2023-06-04 09:17:58 -05:00
hosts.ini Add cloud-init configs 2023-06-04 09:17:58 -05:00
LICENSE Initial commit 2023-06-01 12:02:20 -05:00
README.md Fix README.md 2023-06-01 12:06:49 -05:00
setup.yml Add cloud-init configs 2023-06-04 09:17:58 -05: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:

lxc init images:debian/12/cloud debian-mail --storage lxd-pool

Configure the instance with cloud-init:

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:

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:

lxc start debian-mail 
lxc exec debian-mail -- cloud-init status --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:

[homelab]
10.227.115.42

Run the setup.yml playbook for all roles, or choose specific roles with --tags:

ansible-playbook -i hosts.ini setup.yml -u debian -b
ansible-playbook -i hosts.ini setup.yml --tags debian-mail -u debian -b