GithubHelp home page GithubHelp logo

ansible-pve's Introduction

Table of Content


Note This repo is re-built based on Ansible role to create/delete VM/containers on proxmox as I encountered several issues while testing in my env.

Fixed issue list:

  1. When using vm template to clone a new VM, bootdisk can't be resized. Resolve by running proxmox rest api to resize the bootdisk size.
  2. The VM can't be started after creation. Resolve by adding some sleeping time between main steps.
  3. Ansible role to create/delete containter is not included.
  4. Ansible role to mount new disk is not included.

VM management

Requirements

See requirements.txt.

Use this command to install all requirements:

python3 -m pip install --user -r requirements.txt

ansible-galaxy collection install community.general

Export your vault_pass(Save the vault pass in a safe place, you'll need it to encrypt/decrypt existing vault file)

set +o history
export VAULT_PASSWORD=CHANGEME
set -o history

Modify and setup proxmox credentials in ./roles/ansible-proxmox-vm/defaults/main.yml

Note: Only root@pam account is accepted for full management.

And then encrpyt it with ansible-vault

ansible-vault encrypt ./roles/ansible-proxmox-vm/defaults/main.yml

Role Variables

See ./roles/ansible-proxmox-vm/defaults/globals.yml for the complete list of variables.

See also proxmox_kvm module page.

Dependencies

Module community.general.proxmox_kvm that can be found in collection community.general.

Usage

Define a list of virtual machines in this format:

vm_list:
  - name: ansible-vm-test
    cores: 1
    memory: 2048
    clone: 'template-ubuntu2204-ci'
    #ostype: 'l26'
    target: 'home-proxmox'
    pool: 'test-local'
    ipconfig:
      ipconfig0: 'ip=dhcp'
      #ipconfig0: 'ip=192.168.1.2/26, gw=192.168.1.1'
    net:
      net0: 'virtio,bridge=vmbr1'
    searchdomains: 'homelab.mylocal'
    nameservers: '192.168.1.1'
    ciuser: 'root'
    cipassword: 'CHANGEME123' # password of the new vm, no need to specify it if using ssh key
    sshkeys: 'ssh-rsa AxxxxCM= root@my-pc'

If you don't want to creat new vmlist file as vars, the default one under ./roles/ansible-proxmox-vm/defaults/main/vmlist will be used.

Execute playbook with tags:

# To create VMs as defined under `./roles/ansible-proxmox-vm/defaults/main/vmlist`
ansible-playbook runsetup_vm.yml -t "create"

vm creation1

vm creation2

vm creation3

vm creation4

# To destroy VMs as defined under `./roles/ansible-proxmox-vm/defaults/main/vmlist`
ansible-playbook runsetup_vm.yml -t "stop" # stop the vm before destroy it
ansible-playbook runsetup_vm.yml -t "delete"

vm deletion

Mount new disk

If you wan to add additional disk other than the boot disk, try disk-mount role.

Requirements

Export your vault_pass (ignore this step if it's done)

set +o history
export VAULT_PASSWORD=CHANGEME
set -o history

Modify and setup proxmox credentials in ./roles/disk-mount/vars/main.yml

And then encrpyt it with ansible-vault

ansible-vault encrypt ./roles/disk-mount/vars/main.yml

Dependencies

Module community.general.proxmox_kvm that can be found in collection community.general.

Usage

By default, sdb device will be added after assigning new disk to a VM at the first time and scsi1 will be used to set the disk name. More settings, check ./roles/disk-mount/defaults/main.yml

Check inventory to ensure the VM is defined correctly under vm_mount section.

Execute playbook with tags:

ansible-playbook runsetup_mount_sdb.yml -t "mount"

disk mount1

disk mount2

Container Management

Same requriements and dependencies with VM management.

Usage

Define a list of virtual machines in this format:

vm_list:
  - hostname: ansible-ct-test
    cores: 1
    memory: 2048
    ostemplate: 'local:vztmpl/ubuntu-standard_amd64.tar.zst'
    pool: 'test-local'
    disk: 5
    netif:
      net0: 'name=eth0,ip=dhcp,bridge=vmbr1'
    searchdomain: 'homelab.mylocal'
    nameserver: '192.168.1.1'
    password: 'CHANGEME123'
    pubkey: 'ssh-rsa xxxxxxxxCM= root@MY-PC'

If you don't want to creat new vmlist file as vars, the default one under ./roles/ansible-proxmox-vm/defaults/main/vmlist will be used.

Execute playbook with tags:

# To create and start containers as defined under `./roles/ansible-proxmox-ct/defaults/main/vmlist`
ansible-playbook runsetup_ct.yml -t "create"
ansible-playbook runsetup_ct.yml -t "start"
# To destroy VMs as defined under `./roles/ansible-proxmox-ct/defaults/main/vmlist`
ansible-playbook runsetup_ct.yml -t "stop" # stop the container before you can destroy it
ansible-playbook runsetup_ct.yml -t "delete"

create ct

delete ct

ansible-pve's People

Contributors

kkkimiko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.