AnsiblePlaybooks
End-to-end automation for creating Proxmox LXC guests and hardening their SSH access.
Layout
playbooks/site.yml– Main playbook that provisions LXCs on Proxmox, then configures them.roles/proxmox_lxc– Interacts with the Proxmox API to create, start, and manage LXC containers, and dynamically adds new containers to the inventory.roles/lxc_general– Configures user accounts, syncs SSH keys, applies SSH hardening and firewall rules inside the LXCs.roles/lxc_networking– (Optional) Configures Nginx reverse proxy and manages Let's Encrypt certificates.
Adding a New Container
- Edit
inventory/group_vars/proxmox/main.ymland add a new container entry to theproxmox_lxc_instanceslist with required parameters likename,vmid,cores,memory,ip_octet, etc. - Optionally define any extra roles for that container by adding
extra_rolesto the container entry. - Save your changes.
- Run the playbook to provision and configure the container.
- The container will be created on Proxmox, started, added dynamically to the
new_lxcsgroup, then configured with users, SSH keys, firewall, and any extra roles.
Adding New SSH Keys for Access
- Update the SSH keys file that your configuration fetches, currently defined by
lxc_general_authorized_keys_urlingroup_vars/all.ymlor other relevant group vars. - Add the new public keys to that remote URL or the file path your setup uses.
- Run the playbook again on the target hosts or the
new_lxcsgroup to sync the new keys: - This will update the authorized keys for the configured administrative user without recreating containers.