Skip to content
master
Switch branches/tags
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Ansible Roles: Proxmox

This is a role to setup a new container. Note that you must have root ssh to a proxmox node configured. You must also have api access to your proxmox host/cluster.

This role will primarily run on the ansible localhost. Some tasks will use the "delegate_to" option to run on the remote Proxmox node.

Role Variables

Lots of variables are available to use for provisioning a container. Required will depend on your use case. Most are optional.

Simple Container:

pve_node: pve1
pve_apiuser: root@pam
pve_apipass: myAPIpassword
pve_hostname: "newhostname"
pve_template: local:vztmpl/debian-9.0-standard_9.5-1_amd64.tar.gz

Detailed example with bind mounts from the Proxmox node. I added a cephfs mount to my cluster, so it's mounted on each Proxmox node:

pve_node: pve1
pve_vmid: 114
pve_apiuser: engonzal@pve
pve_apipass: myAPIpassword
pve_api_host: pve1.domain.com
pve_hostname: "newhostname"
pve_template: local:vztmpl/debian-9.0-standard_9.5-1_amd64.tar.gz
pve_netif:
  net0: "name=eth0,gw=192.168.84.1,ip=192.168.84.20/24,bridge=vmbr0"
pve_cores: 2
pve_mem: 2048
pve_swap: "{{ pve_mem }}"
pve_guest_pass: myContainerRootPassword
pve_search: domain.com
pve_dns: '192.168.84.1'
pve_storage: ceph_storage_ct
pve_unprivileged: yes
pve_ssh: "ssh-rsa myPublicKey engonzal@hostname"
pve_custom_mounts:
  mp0: "/mnt/pve/cephfs_data/downloads/,mp=/downloads"
  mp1: "/mnt/pve/cephfs_data/media,mp=/media"

Example Playbook

Ansible hosts inventory file

# hosts
[proxmox_containers]
test_server

Ansible playbook

# proxmox.yml
---
- hosts: plex_app
  connection: local
  user: root
  vars:
    pve_node: pve1
    pve_apiuser: root@pam
    pve_apipass: myAPIpassword
    pve_api_host: pve1.domain.com
    pve_hostname: "newhostname"
    pve_template: local:vztmpl/debian-9.0-standard_9.5-1_amd64.tar.gz
  roles:
    - engonzal.proxmox

Ansible run command

ansible-playbook -i hosts -l test_server proxmox.yml

Example Playbook (advanced)

You can also add a delay after your play if you have other plays to run after:

---
- hosts: plex_app
  connection: local
  user: root
  pre_tasks:
  - name: get current python interpreter (for pip virtualenvs)
    command: which python
    register: which_interpreter
    tags: always
    changed_when: False

  - name: Use the current python path instead of system python
    set_fact:
      ansible_python_interpreter: "{{ which_interpreter.stdout }}"
    tags: always

  roles:
    - name: engonzal.proxmox
      tags: pve
  post_tasks:
    - name: Allow container time to boot if started
      pause:
        seconds: 20
      when: pve_info_state.changed

- hosts: plex_app
  user: root
  vars:
    ansible_python_interpreter: /usr/bin/python3 # needed for bionic ct
    package_list:
      - vim
  roles:
    - engonzal.package

Other Examples

DHCP Example:

pve_node: pve1
pve_vmid: 114
pve_apiuser: engonzal@pve
pve_apipass: myAPIpassword
pve_api_host: pve1.domain.com
pve_state: present
pve_hostname: "newhostname"
pve_template: local:vztmpl/debian-9.0-standard_9.5-1_amd64.tar.gz
pve_netif:
  net0: "name=eth0,ip=dhcp,ip6=dhcp,bridge=vmbr0"
pve_storage: local-lvm
pve_custom_mounts:
  mp0: "/mnt/pve/cephfs_data/downloads/,mp=/downloads"
  mp1: "/mnt/pve/cephfs_data/media,mp=/media"

Organization

For my uses I organize the variables like this (using ansible vault to encrypt passwords):

# group_vars/all
pve_apiuser: engonzal@pve
pve_apipass: myAPIpassword
pve_api_host: pve1.domain.com
pve_guest_pass: myContainerRootPassword
pve_search: domain.com
pve_dns: '192.168.84.1'
pve_unprivileged: yes
pve_ssh: "ssh-rsa myPublicKey engonzal@hostname"

# group_vars/plex
pve_node: pve3
pve_vmid: 114
pve_hostname: "plex"
pve_netif:
  net0: "name=eth0,gw=192.168.84.1,ip=192.168.84.20/24,bridge=vmbr0"
pve_template: local:vztmpl/ubuntu-18.10-standard_18.10-1_amd64.tar.gz
pve_cores: 8
pve_mem: 4096
pve_custom_mounts:
  mp0: "/mnt/pve/cephfs_data/media,mp=/media"

License

BSD

About

Ansible role to provision containers in Proxmox VE virtualization

Topics

Resources

Packages

No packages published

Languages