0

I have a problem with the dynamic inventory that I want to have generated by the Proxmox. I have created an inventory.proxmox.yml file. This contains the following config:

plugin: community.general.proxmox
url: https://MyIP:8006
user: ansible@pve
password: my_password
validate_certs: false
want_proxmox_nodes_ansible_host: false

In the next step I want to create the inventory. For this I proceed as follows:

ansible-inventory -i inventory.proxmox.yml --list

After executing, I receive the following error:

/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1015: InsecureRequestWarning: Unverified HTTPS request is being made to host 'myIP'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  warnings.warn(
[WARNING]:  * Failed to parse /home/user/ansible/inventory/inventory.proxmox.yml with auto plugin: 'NoneType' object is not subscriptable
[WARNING]:  * Failed to parse /home/user/ansible/inventory/inventory.proxmox.yml with yaml plugin: Plugin configuration YAML file, not YAML inventory
[WARNING]:  * Failed to parse /home/user/ansible/inventory/inventory.proxmox.yml with ini plugin: Invalid host pattern 'plugin:' supplied, ending in ':' is not
allowed, this character is reserved to provide a port.
[WARNING]:  * Failed to parse /home/user/ansible/inventory/inventory.proxmox.yml with ansible_collections.community.general.plugins.inventory.proxmox plugin:
'NoneType' object is not subscriptable
[WARNING]: Unable to parse /home/user/ansible/inventory/inventory.proxmox.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available

Changing the "url: https" in my yml-file to "http" does get rid of https-error. However, the proxmox is not listening on http.

twet
  • 11
  • 2
  • I don't understand. Where does the inventory get's build from? From proxmox? Or are you manually configuring the inventory? – Kevin C Nov 14 '22 at 14:00
  • Hi, i've manually created the inventory. However, the goal is to read all existing VMs including hostname/IPs from the proxmox and use them as inventory. – twet Nov 14 '22 at 14:31
  • Why? Will you build/break the vm's that often? Why not configure it once in the inventory file? – Kevin C Nov 14 '22 at 14:34

2 Answers2

0

I had a similar problem:

[WARNING]:  * Failed to parse pve.yml with auto plugin: inventory source 'pve.yml' could not be verified by inventory plugin 'community.general.proxmox'
[WARNING]:  * Failed to parse pve.yml with yaml plugin: Plugin configuration YAML file, not YAML inventory
[WARNING]:  * Failed to parse pve.yml with ini plugin: Invalid host pattern 'plugin:' supplied, ending in ':' is not allowed, this character is reserved to provide a port.
[WARNING]: Unable to parse pve.yml as an inventory source
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
[WARNING]: Could not match supplied host pattern, ignoring: pve

The problem turned out to be rather stupid and unexpected. I got into the code of the module itself and found this:

self.display.vvv('Skipping due to inventory source not ending in "proxmox.yaml" nor "proxmox.yml"')

All options with the ending *.proxmox.yml didn't work in my case (e.g. my.proxmox.yml). So I just renamed my inventory file to proxmox.yml and it worked. My inventory:

plugin: community.general.proxmox
url: https://my.pve.host:8006
user: ansible-prov@pve
token_id: ansible
token_secret: <token>
validate_certs: false
want_proxmox_nodes_ansible_host: false
compose:
  ansible_host: proxmox_ipconfig0.ip | default(proxmox_net0.ip) | ipaddr('address')
Dexogen
  • 1
  • 1
0

TLDR

append , 'realm': 'pve', )} to line 277 on file ~/.ansible/collections/ansible_collections/community/general/plugins/inventory/proxmox.py and change your inventory.proxmox.yml from ansible@pve to ansible


I ran into the same issue but @Dexogen is on the wrong track with a different problem unfortunately. I can certainly name the file anything I wish.

I tested:

proxmox.yaml
proxmox.yml
inventory.proxmox.yaml
inventory.proxmox.yml

all worked with my fix below


I am on Proxmox: 7.1-11

The problem is that we are using password: and looking at the requests sent, we are sending a POST with the body:

username=root%40pve&password:xxxxx

which is returning a 401

I compared that to the login from the web and they use &realm=pve in the body

When I edited line 277 from the proxmox.py file from:

... 'password': self.proxmox_password, })

to

... 'password': self.proxmox_password, 'realm': 'pve' })

You can find this file at:

~/.ansible/collections/ansible_collections/community/general/plugins/inventory/proxmox.py

And change your inventory.proxmox.yml file from:

...
user: ansible@pve
...

To

...
user: ansible
...

By my testing, it should work then!

I'll investigate more and see if I can raise a PR

Ari
  • 745
  • 1
  • 7
  • 23