community.general.proxmox (1.3.14) — module

management of instances in Proxmox VE cluster

Authors: Sergei Antipov (@UnderGreen)

Install collection

Install with ansible-galaxy collection install community.general:==1.3.14


Add to requirements.yml

  collections:
    - name: community.general
      version: 1.3.14

Description

allows you to create/delete/stop instances in Proxmox VE cluster

Starting in Ansible 2.1, it automatically detects containerization type (lxc for PVE 4, openvz for older)

From community.general 4.0.0 on, there will be no default values, see I(proxmox_default_behavior).


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create new container with minimal options
  community.general.proxmox:
    vmid: 100
    node: uk-mc02
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    password: 123456
    hostname: example.org
    ostemplate: 'local:vztmpl/ubuntu-14.04-x86_64.tar.gz'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create new container with hookscript and description
  community.general.proxmox:
    vmid: 100
    node: uk-mc02
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    password: 123456
    hostname: example.org
    ostemplate: 'local:vztmpl/ubuntu-14.04-x86_64.tar.gz'
    hookscript: 'local:snippets/vm_hook.sh'
    description: created with ansible
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create new container automatically selecting the next available vmid.
  community.general.proxmox:
    node: 'uk-mc02'
    api_user: 'root@pam'
    api_password: '1q2w3e'
    api_host: 'node1'
    password: '123456'
    hostname: 'example.org'
    ostemplate: 'local:vztmpl/ubuntu-14.04-x86_64.tar.gz'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create new container with minimal options with force(it will rewrite existing container)
  community.general.proxmox:
    vmid: 100
    node: uk-mc02
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    password: 123456
    hostname: example.org
    ostemplate: 'local:vztmpl/ubuntu-14.04-x86_64.tar.gz'
    force: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create new container with minimal options use environment PROXMOX_PASSWORD variable(you should export it before)
  community.general.proxmox:
    vmid: 100
    node: uk-mc02
    api_user: root@pam
    api_host: node1
    password: 123456
    hostname: example.org
    ostemplate: 'local:vztmpl/ubuntu-14.04-x86_64.tar.gz'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create new container with minimal options defining network interface with dhcp
  community.general.proxmox:
    vmid: 100
    node: uk-mc02
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    password: 123456
    hostname: example.org
    ostemplate: 'local:vztmpl/ubuntu-14.04-x86_64.tar.gz'
    netif: '{"net0":"name=eth0,ip=dhcp,ip6=dhcp,bridge=vmbr0"}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create new container with minimal options defining network interface with static ip
  community.general.proxmox:
    vmid: 100
    node: uk-mc02
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    password: 123456
    hostname: example.org
    ostemplate: 'local:vztmpl/ubuntu-14.04-x86_64.tar.gz'
    netif: '{"net0":"name=eth0,gw=192.168.0.1,ip=192.168.0.2/24,bridge=vmbr0"}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create new container with minimal options defining a mount with 8GB
  community.general.proxmox:
    vmid: 100
    node: uk-mc02
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    password: 123456
    hostname: example.org
    ostemplate: local:vztmpl/ubuntu-14.04-x86_64.tar.gz'
    mounts: '{"mp0":"local:8,mp=/mnt/test/"}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create new container with minimal options defining a cpu core limit
  community.general.proxmox:
    vmid: 100
    node: uk-mc02
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    password: 123456
    hostname: example.org
    ostemplate: local:vztmpl/ubuntu-14.04-x86_64.tar.gz'
    cores: 2
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Start container
  community.general.proxmox:
    vmid: 100
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    state: started
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: >
    Start container with mount. You should enter a 90-second timeout because servers
    with additional disks take longer to boot
  community.general.proxmox:
    vmid: 100
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    state: started
    timeout: 90
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Stop container
  community.general.proxmox:
    vmid: 100
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    state: stopped
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Stop container with force
  community.general.proxmox:
    vmid: 100
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    force: yes
    state: stopped
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Restart container(stopped or mounted container you can't restart)
  community.general.proxmox:
    vmid: 100
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    state: restarted
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove container
  community.general.proxmox:
    vmid: 100
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    state: absent

Inputs

    
cpus:
    description:
    - numbers of allocated cpus for instance
    - If I(proxmox_default_behavior) is set to C(compatiblity) (the default value), this
      option has a default of C(1). Note that the default value of I(proxmox_default_behavior)
      changes in community.general 4.0.0.
    type: int

disk:
    description:
    - hard disk size in GB for instance
    - If I(proxmox_default_behavior) is set to C(compatiblity) (the default value), this
      option has a default of C(3). Note that the default value of I(proxmox_default_behavior)
      changes in community.general 4.0.0.
    type: str

node:
    description:
    - Proxmox VE node, when new VM will be created
    - required only for C(state=present)
    - for another states will be autodiscovered
    type: str

pool:
    description:
    - Proxmox VE resource pool
    type: str

swap:
    description:
    - swap memory size in MB for instance
    - If I(proxmox_default_behavior) is set to C(compatiblity) (the default value), this
      option has a default of C(0). Note that the default value of I(proxmox_default_behavior)
      changes in community.general 4.0.0.
    type: int

vmid:
    description:
    - the instance id
    - if not set, the next available VM ID will be fetched from ProxmoxAPI.
    - if not set, will be fetched from PromoxAPI based on the hostname
    type: str

cores:
    description:
    - Specify number of cores per socket.
    - If I(proxmox_default_behavior) is set to C(compatiblity) (the default value), this
      option has a default of C(1). Note that the default value of I(proxmox_default_behavior)
      changes in community.general 4.0.0.
    type: int

force:
    default: 'no'
    description:
    - forcing operations
    - can be used only with states C(present), C(stopped), C(restarted)
    - with C(state=present) force option allow to overwrite existing container
    - with states C(stopped) , C(restarted) allow to force stop instance
    type: bool

netif:
    description:
    - specifies network interfaces for the container. As a hash/dictionary defining interfaces.
    type: dict

state:
    choices:
    - present
    - started
    - absent
    - stopped
    - restarted
    default: present
    description:
    - Indicate desired state of the instance
    type: str

memory:
    description:
    - memory size in MB for instance
    - If I(proxmox_default_behavior) is set to C(compatiblity) (the default value), this
      option has a default of C(512). Note that the default value of I(proxmox_default_behavior)
      changes in community.general 4.0.0.
    type: int

mounts:
    description:
    - specifies additional mounts (separate disks) for the container. As a hash/dictionary
      defining mount points
    type: dict

onboot:
    description:
    - specifies whether a VM will be started during system bootup
    - If I(proxmox_default_behavior) is set to C(compatiblity) (the default value), this
      option has a default of C(no). Note that the default value of I(proxmox_default_behavior)
      changes in community.general 4.0.0.
    type: bool

pubkey:
    description:
    - Public key to add to /root/.ssh/authorized_keys. This was added on Proxmox 4.2,
      it is ignored for earlier versions
    type: str

storage:
    default: local
    description:
    - target storage
    type: str

timeout:
    default: 30
    description:
    - timeout for operations
    type: int

api_host:
    description:
    - the host of the Proxmox VE cluster
    required: true
    type: str

api_user:
    description:
    - the user to authenticate with
    required: true
    type: str

cpuunits:
    description:
    - CPU weight for a VM
    - If I(proxmox_default_behavior) is set to C(compatiblity) (the default value), this
      option has a default of C(1000). Note that the default value of I(proxmox_default_behavior)
      changes in community.general 4.0.0.
    type: int

hostname:
    description:
    - the instance hostname
    - required only for C(state=present)
    - must be unique if vmid is not passed
    type: str

password:
    description:
    - the instance root password
    type: str

hookscript:
    description:
    - Script that will be executed during various steps in the containers lifetime.
    type: str
    version_added: 0.2.0
    version_added_collection: community.general

ip_address:
    description:
    - specifies the address the container will be assigned
    type: str

nameserver:
    description:
    - sets DNS server IP address for a container
    type: str

ostemplate:
    description:
    - the template for VM creating
    - required only for C(state=present)
    type: str

description:
    description:
    - Specify the description for the container. Only used on the configuration web interface.
    - This is saved as a comment inside the configuration file.
    type: str
    version_added: 0.2.0
    version_added_collection: community.general

api_password:
    description:
    - the password to authenticate with
    - you can use PROXMOX_PASSWORD environment variable
    type: str

api_token_id:
    description:
    - Specify the token ID.
    type: str
    version_added: 1.3.0
    version_added_collection: community.general

searchdomain:
    description:
    - sets DNS search domain for a container
    type: str

unprivileged:
    default: 'no'
    description:
    - Indicate if the container should be unprivileged
    type: bool

validate_certs:
    default: 'no'
    description:
    - enable / disable https certificate verification
    type: bool

api_token_secret:
    description:
    - Specify the token secret.
    type: str
    version_added: 1.3.0
    version_added_collection: community.general

proxmox_default_behavior:
    choices:
    - compatibility
    - no_defaults
    description:
    - Various module options used to have default values. This cause problems when user
      expects different behavior from proxmox by default or fill options which cause problems
      when they have been set.
    - The default value is C(compatibility), which will ensure that the default values
      are used when the values are not explicitly specified by the user.
    - From community.general 4.0.0 on, the default value will switch to C(no_defaults).
      To avoid deprecation warnings, please set I(proxmox_default_behavior) to an explicit
      value.
    - This affects the I(disk), I(cores), I(cpus), I(memory), I(onboot), I(swap), I(cpuunits)
      options.
    type: str
    version_added: 1.3.0
    version_added_collection: community.general