Skip to content

Ansible playbook to create a virtual machine with Proxmox and install a distribution on it.

Notifications You must be signed in to change notification settings

Fosten/proxmox-deploy-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ansible Proxmox Deployment

This Ansible playbook utilizes proxmoxer, cloud-init, and Qemu/KVM Virtual Machine Manager to deploy Virtual Machines.

Install prereqs

Setup the Proxmox Node for ansible communication

Login to your proxmox node and run the following commands.

apt install -y python3-pip build-essential
pip3 install --upgrade pip
pip3 install virtualenv
pip3 install proxmoxer

Download the Debian cloud image and create a VM template with cloud-init

Adjust the VM IDs below to your preference. You will need to su - root to set the environment for qm command.

wget https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-generic-amd64.qcow2
qm create 400 --name "debian-2022-template" --memory 4096 --net0 virtio,bridge=vmbr0 --cores 2
qm importdisk 400 ~/debian-11-generic-amd64.qcow2 local-lvm
qm set 400 --scsihw virtio-scsi-pci --virtio0 local-lvm:vm-400-disk-0
qm set 400 --boot c --bootdisk virtio0
qm set 400 --ide2 local-lvm:cloudinit
qm set 400 --agent 1
qm template 400

Clone template for Ansible Host

Replace the IP addresses below to match your desired environment.

qm clone 400 401 --name vm-ansible-host
qm set 401 --sshkey ~/.ssh/id_rsa.pub
qm set 401 --ipconfig0 ip=x.x.x.x/x,gw=x.x.x.x

The 2GB disk Proxmox gives you by default is insufficient to run this script. However, due to this bug Debian cloud-init images will get Kernel Panic upon first boot after using qm resize. So the VM will need to be started twice:

qm resize 401 virtio0 16G
qm start 401
qm stop 401
qm start 401

Setup the Ansible Host

When using cloud-init, there is no password and no root login, but we can establish a connection using the SSH key we created in the last step.

From the proxmox node, ssh [email protected] and do some basic setup, such as:

sudo adduser user
sudo usermod -aG sudo user
su - user
sudo sed -i 's/[#]*Port 22/Port 3333/g' /etc/ssh/sshd_config
sudo sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
sudo service sshd restart
sudo passwd root

Then install some programs you'll need, set the environment, and clone the repo.

sudo apt install python3 python3-pip sshpass git -y
pip3 install ansible
echo 'export PATH=/home/user/.local/bin:$PATH' >>~/.bash_profile
source ~/.bash_profile
git clone https://github.com/Fosten/proxmox-deploy-project.git

Deploy a new VM

Now that everything is installed, to deploy more VMs in the future, you can just repeat the commands below.

Edit the Hosts File

cd proxmox-deploy-project
nano hosts

Change the following (ssl_verify and ansible_ssh_extra_args can stay the same):

api_node= (Name of Proxmox Node)
api_user= (User with GUI access)
ansible_host= (IP of Proxmox Node)
ansible_user= (User with SSH access)
ansible_ssh_port= (Port to access SSH)
ansible_ssh_private_key_file= (Path to ssh key)

Run the installer

make install

About

Ansible playbook to create a virtual machine with Proxmox and install a distribution on it.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published