2.3 KiB
Ansible Playbook for Proxmox VM Management
This Ansible playbook automates the creation, deletion, and configuration of virtual machines (VMs) on a Proxmox server.
Prerequisites
- Ansible installed on the local machine
- Ansible community.general.proxmox_kvm module
- Access to a Proxmox server with API access enabled
- Python
proxmoxerlibrary installed (pip install proxmoxer)
Setup
-
Clone this repository:
git clone https://github.com/TheTaqiTahmid/proxmox_ansible_automation -
Update the
inventoryfile with your Proxmox server details:all: hosts: proxmox: ansible_host: your_proxmox_ip ansible_user: your_proxmox_user ansible_password: your_proxmox_passwordIn the current example implementation in
inventories/hosts.yaml, there are multiple groups depending on the types of hosts. -
Add group-related variables to the group file under the
group_varsdirectory and individual host-related variables to the files under thehost_varsdirectory. Ansible will automatically pick up these variables.
Playbooks
Create VM
To create the VMs, run the following command:
ansible-playbook playbooks/create-vms.yaml
The playbook can be run against specific Proxmox instance using:
ansible-playbook playbooks/create-vms.yaml --limit proxmox1
Delete VM
To delete existing VMs, run the following command:
ansible-playbook playbooks/destroy-vms.yaml
Similarly the destory playbook can be run against specific Proxmox instance using:
ansible-playbook playbooks/destroy-vms.yaml --limit proxmox1
Configure VM
To configure an existing VM, run the following command:
ansible-playbook playbooks/configure-vms.yaml
The configuration can be limited to individual VMs using limits:
ansible-playbook playbooks/configure-vms.yaml --limit vm6
Variables
The playbooks use the following variables, which can be customized in the
group_vars/proxmox.yml file:
vm_id: The ID of the VMvm_name: The name of the VMvm_memory: The amount of memory for the VMvm_cores: The number of CPU cores for the VMvm_disk_size: The size of the VM disk
Author
- Taqi Tahmid (mdtaqitahmid@gmail.com)