Ansible Dynamic Inventory for Proxmox

I’ve been playing with Ansible lately as part of my RHCA studies, and found a nice way of using dynamic inventory to manage my Proxmox homelab.


On the Ansible control node, change to the folder where playbooks are stored:

$ cd /home/ansible/playbooks

Download the script from

$ git clone

Make it executable:

$ chmod 0755 ./


Try listing dynamic inventory:

$ ./ \
  --url= \
  --username=root@pam \
  --password=changeme \
  --list --pretty
  "all": {
    "hosts": [

Create a file with environment variables to store Proxmox credentials:

export PROXMOX_USERNAME=root@pam
export PROXMOX_PASSWORD=changeme

Execute commands from filename in the current shell environment:

$ source ./

List dynamic inventory without passing credentials on the CLI:

$ ./ --list --pretty

Use inventory with Ansible:

$ ansible all -i ./ -m ping -u ansible
ansible5.hl.local | SUCCESS => {
    "changed": false, 
    "ping": "pong"
proxy1.hl.local | SUCCESS => {
    "changed": false, 
    "ping": "pong"

4 thoughts on “Ansible Dynamic Inventory for Proxmox

  1. Connecting to (||:443… connected.
    HTTP request sent, awaiting response… 404 Not Found
    2020-07-09 07:57:14 ERROR 404: Not Found.

  2. get error TypeError: the JSON object must be str, not ‘bytes’
    ./ –list Traceback (most recent call last): File “./”, line 391, in main() File “./”, line 376, in main data = main_list(options, config_path) File “./”, line 248, in main_list proxmox_api.auth() File “./”, line 146, in auth validate_certs=self.options.validate)) File “/usr/lib/python3.5/json/”, line 268, in load parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) File “/usr/lib/python3.5/json/”, line 312, in loads s.__class__.__name__)) TypeError: the JSON object must be str, not ‘bytes’

    Python 3.5.3

    does it work for you?

  3. I keep getting back the wrong IP address for my VMs.
    I eventually got it working by changing the at about lines 260-262 to this,
    pattern = re.compile(“192”)
    system_info.ip_address = ip_address[‘ip-address’]
    the addresses on my network start with 192, so i want those ones.
    someone with better Python skills might be able to do something better :-)

Leave a Reply

Your email address will not be published. Required fields are marked *