mirror of
https://codeberg.org/hyperreal/ansible-homelab
synced 2024-11-01 16:43:09 +01:00
87 lines
2.0 KiB
Org Mode
87 lines
2.0 KiB
Org Mode
|
* 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:
|
||
|
|
||
|
#+begin_src shell
|
||
|
lxc init images:debian/12/cloud debian-archive --storage lxd-pool
|
||
|
#+end_src
|
||
|
|
||
|
Configure the instance for cloud-init:
|
||
|
|
||
|
#+begin_src shell
|
||
|
lxc config set debian-archive cloud-init.user-data - <<- EOF
|
||
|
#cloud-config
|
||
|
users:
|
||
|
- name: debian
|
||
|
ssh_authorized_keys:
|
||
|
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIOmibToJQ8JZpSFLH3482oxvpD56QAfu4ndoofbew5t jas@si.local
|
||
|
sudo: 'ALL=(ALL) NOPASSWD: ALL'
|
||
|
shell: /bin/bash
|
||
|
lock_passwd: true
|
||
|
apt:
|
||
|
sources_list: |
|
||
|
deb http://deb.debian.org/debian $RELEASE main
|
||
|
deb http://deb.debian.org/debian $RELEASE-updates main
|
||
|
deb http://deb.debian.org/debian-security/ $RELEASE-security main
|
||
|
deb http://deb.debian.org/debian $RELEASE-backports
|
||
|
package_update: true
|
||
|
package_upgrade: true
|
||
|
packages:
|
||
|
- curl
|
||
|
- debian-keyring
|
||
|
- debsig-verify
|
||
|
- git
|
||
|
- nodejs
|
||
|
- npm
|
||
|
- notmuch
|
||
|
- offlineimap3
|
||
|
- pass
|
||
|
- python3-dev
|
||
|
- python3-pip
|
||
|
- ripgrep
|
||
|
- ssh
|
||
|
- wget
|
||
|
- xauth
|
||
|
- youtube-dl
|
||
|
rsyslog:
|
||
|
configs:
|
||
|
- content: "*.* @10.0.0.41:514"
|
||
|
filename: 99-forward.conf
|
||
|
remotes:
|
||
|
moonshadow: 10.0.0.41
|
||
|
timezone: America/Chicago
|
||
|
EOF
|
||
|
#+end_src
|
||
|
|
||
|
Start the instance, then check the cloud-init status:
|
||
|
|
||
|
#+begin_src shell
|
||
|
lxc start debian-archive
|
||
|
lxc exec debian-archive -- cloud-init status --wait
|
||
|
#+end_src
|
||
|
|
||
|
SSH into the new instance to accept the host key:
|
||
|
|
||
|
#+begin_src shell
|
||
|
ssh debian@10.227.115.42
|
||
|
#+end_src
|
||
|
|
||
|
Once that's done, you should be able to SSH directly to the debian user, and Ansible will be ready to run.
|
||
|
|
||
|
Add the instance's IP address to hosts.ini:
|
||
|
|
||
|
#+begin_src yaml
|
||
|
[homelab]
|
||
|
10.227.115.42
|
||
|
#+end_src
|
||
|
|
||
|
Run the setup.yml playbook for all roles, or choose specific roles with --tags:
|
||
|
|
||
|
#+begin_src shell
|
||
|
ansible-playbook -i hosts.ini setup.yml -u debian -b
|
||
|
ansible-playbook -i hosts.ini setup.yml --tags debian-archive -u debian -b
|
||
|
#+end_src
|