- add new playbook to spin-up kubernetes cluster using k0sctl and k0sctl config file
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. -
Add the following secrets to the ansible-vault:
- proxmox_api_token_id
- proxmox_api_token
- ansible_proxmox_user
- ansible_vm_user
- proxmox_user
- ansible_ssh_private_key_file
- ciuser
- cipassword
One can create the secret file using the following command:
ansible-vault create secrets/vault.yml
To encrypt and decrypt the file, use the following commands:
ansible-vault encrypt secrets/vault.yml
ansible-vault decrypt secrets/vault.yml
The password for vault file can be stored in a file or can be provided during
the encryption/decryption process. The password file location can be specified
in the ansible.cfg file.
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)