maxhoesel.proxmox.lxc_container role – Creates and bootstraps a LXC container on a Proxmox VE node for usage with Ansible

Note

This role is part of the maxhoesel.proxmox collection (version 5.1.1).

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it use: ansible-galaxy collection install maxhoesel.proxmox.

To use it in a playbook, specify: maxhoesel.proxmox.lxc_container.

Entry point main – Creates and bootstraps a LXC container on a Proxmox VE node for usage with Ansible

Synopsis

  • This role creates a new LXC container on a proxmox host, connects to it over the proxmox hosts shell and bootstraps it by installing a SSH server and Python. This then allows for access from Ansible like normal.

  • To execute this role, Ansible needs to access the Proxmox host on which the container will be created. To speficy the host, set pve_host to the hots’ inventory name. If you don’t want to add the host to your inventory file, you can also add it at runtime with the add_host module - see the role README for an example.

  • This role has been tested on the following container templates: - Ubuntu 20.04 - Debian 10 - Fedora 32 - CentOS 7/8 - OpenSUSE 15.2 - Alpine 3.12 Other distributions should work as well, as long as they: - use a package manager also used by one of the above distros - use systemd for service management (or rc for Alpine)

  • The following python modules are required on the controller: - proxmoxer - requests

  • The main use for this role is to create an Ansible-compatible container image for consumption by the lxc_container_to_ostemplate role that you can then deploy with Ansible directly. If you are looking for a more general solution to deploy LXC containers, I recommend looking into the community.general.proxmox module (that also powers this role) or, for a more Infrastructure-as-Code oriented approach, Terraform.

Parameters

Parameter

Comments

lxccreate_args

dictionary

Additional arguments to be passed to the proxmox module when creating the container.

See here for details about valid parameters

Default: {"cores": 1, "cpuunits": 1024, "disk": "10", "memory": 1024, "netif": {"net0": "name=eth0,bridge=vmbr0,ip=dhcp,firewall=0"}, "node": "pve", "onboot": false, "storage": "local-lvm", "swap": 0, "unprivileged": true}

lxccreate_bootstrap

boolean

Set this to yes to run a simple bootstrap script on the container after creation.

The script will prepare the container for Ansible (SSH server + Python)

Choices:

  • false

  • true ← (default)

lxccreate_hostname

string / required

Hostname of the LXC container to create

Must be a valid PVE container name

lxccreate_ostemplate

string

OS Template to create the new container from

Default: "local:vztmpl/ubuntu-20.04-standard_20.04-1_amd64.tar.gz"

lxccreate_ostemplate_download

boolean

Automatically download the specified base template from the PVE repository if the image is not present

Choices:

  • false

  • true ← (default)

lxccreate_timeout

integer

Increase this value if you are experiencing timeout errors during PVE API tasks

Default: 120

pve_api_host

string

Hostname under which the PVE API is reachable

This will usually the same as pve_host, except in cases where you are running the API behind a proxy of some sort

Default: "{{ pve_host }}"

pve_api_password

string / required

Password with which to connect to the API

pve_api_user

string

Username with which to connect to the API

Default: "root@pam"

pve_host

string / required

Inventory hostname of the PVE host to create the container on. Ansible will connect to this host.