Ansible for Homelab
This Ansible setup is designed to automate the configuration and maintenance of servers and applications in the homelab. It includes playbooks for common tasks, inventory management for different environments, and a structured way to handle variables and secrets.
Directory Structure
inventory/: Contains the inventory files that define the hosts and groups of hosts managed by Ansible.playbooks/: Contains the Ansible playbooks for various automation tasks.secrets.yml: This file is intended to store sensitive data like passwords and API keys. It is recommended to encrypt this file using Ansible Vault.example_secrets.yml: An example secrets file.vars.yml: This file can be used to store non-sensitive variables that are used across multiple playbooks.
Getting Started
- Install Ansible: Make sure you have Ansible installed on your control machine.
- Inventory: Update the
inventory/hosts.inifile with the IP addresses and connection details for your servers. - Secrets: Create a
secrets.ymlfile based on theexample_secrets.ymltemplate and encrypt it using Ansible Vault for security. - Run a Playbook: You can run a playbook using the
ansible-playbookcommand. For example:ansible-playbook -i inventory/hosts.ini playbooks/apt_upgrade.yml
Proxmox Integration Setup
To use the provisioning playbooks (create_lxc.yml), you must configure Proxmox API access.
1. Requirements on Control Node
Install community.general collection and proxmoxer python library:
sudo apt install python3-proxmoxer # OR pip3 install proxmoxer requests
ansible-galaxy collection install community.general
2. Create Proxmox User & Token
- Create User: In Proxmox, go to Datacenter > Permissions > Users and add
ansible@pve(Proxmox VE authentication). - Create Token: Go to API Tokens, add a token for
ansible@pve(e.g.,ansible-token). Save the Secret! - Permissions: Go to Permissions, add User Permission for
ansible@pve:- Path:
/ - Role:
Administrator(Easiest) - OR Granular Roles:
- Path:
/->PVEVMAdmin+Sys.Audit - Path:
/storage/local(or your storage ID) ->Datastore.AllocateSpace+Datastore.Audit
- Path:
- Path:
3. Configure Secrets
Update your secrets.yml (do not commit this file!) with the credentials:
proxmox_api_user: "ansible@pve"
proxmox_api_token_id: "ansible-token"
proxmox_api_token_secret: "YOUR_SECRET_HERE"
proxmox_node: "proxmox"
proxmox_storage: "local"
Description
Languages
Shell
100%