Repository: ansible-collections/community.general

Issue:
Proxmox inventory plugin
### Summary

If you try to use this plugin for auto discovery inventory, the sample will not work. To make it works you have to set 
`want_facts: yes`

By the way, by default it's no :
```
 want_facts:
        description: Gather LXC/QEMU configuration facts.
        default: no
        type: bool
```
It should be yes by default, if not the plugin is not able to auto create group like keyed_groups defined it.

### Issue Type

Documentation Report

### Component Name

plugin inventory community.general.proxmox

### Ansible Version

_No response_

### Configuration

_No response_

### OS / Environment

_No response_

### Additional Information

community.general version 3.2.0

### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/inventory/cobbler.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/inventory/cobbler.py)
* [`plugins/inventory/gitlab_runners.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/inventory/gitlab_runners.py)
* [`plugins/inventory/linode.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/inventory/linode.py)
* [`plugins/inventory/lxd.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/inventory/lxd.py)
* [`plugins/inventory/nmap.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/inventory/nmap.py)
* [`plugins/inventory/online.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/inventory/online.py)
* [`plugins/inventory/proxmox.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/inventory/proxmox.py)
* [`plugins/inventory/scaleway.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/inventory/scaleway.py)
* [`plugins/inventory/stackpath_compute.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/inventory/stackpath_compute.py)
* [`plugins/inventory/virtualbox.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/inventory/virtualbox.py)
* [`tests/unit/plugins/inventory/__init__.py`](https://github.com/ansible-collections/community.general/blob/master/tests/unit/plugins/inventory/__init__.py)
* [`tests/unit/plugins/inventory/fixtures/lxd_inventory.atd`](https://github.com/ansible-collections/community.general/blob/master/tests/unit/plugins/inventory/fixtures/lxd_inventory.atd)
* [`tests/unit/plugins/inventory/test_cobbler.py`](https://github.com/ansible-collections/community.general/blob/master/tests/unit/plugins/inventory/test_cobbler.py)
* [`tests/unit/plugins/inventory/test_linode.py`](https://github.com/ansible-collections/community.general/blob/master/tests/unit/plugins/inventory/test_linode.py)
* [`tests/unit/plugins/inventory/test_lxd.py`](https://github.com/ansible-collections/community.general/blob/master/tests/unit/plugins/inventory/test_lxd.py)
* [`tests/unit/plugins/inventory/test_proxmox.py`](https://github.com/ansible-collections/community.general/blob/master/tests/unit/plugins/inventory/test_proxmox.py)
* [`tests/unit/plugins/inventory/test_stackpath_compute.py`](https://github.com/ansible-collections/community.general/blob/master/tests/unit/plugins/inventory/test_stackpath_compute.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @Ajpantuso @Charliekenney23 @InTheCloudDan @LBGarber @QuentinBrosse @Thulium-Drake @abarbare @conloos @decentral1se @displague @ilijamt @jerome-quere @joshainglis @karmab @kindermoumoute @remyleone @rmcintosh @sieben @tleguern
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
!component -plugins/inventory/cobbler.py
!component -plugins/inventory/gitlab_runners.py
!component -plugins/inventory/linode.py
!component -plugins/inventory/lxd.py
!component -plugins/inventory/nmap.py
!component -plugins/inventory/online.py
!component -plugins/inventory/scaleway.py
!component -plugins/inventory/stackpath_compute.py
!component -plugins/inventory/virtualbox.py
!component -tests/unit/plugins/inventory/__init__.py
!component -tests/unit/plugins/inventory/fixtures/lxd_inventory.atd
!component -tests/unit/plugins/inventory/test_cobbler.py
!component -tests/unit/plugins/inventory/test_linode.py
!component -tests/unit/plugins/inventory/test_lxd.py
!component -tests/unit/plugins/inventory/test_proxmox.py
!component -tests/unit/plugins/inventory/test_stackpath_compute.py
Files identified in the description:
* [`plugins/inventory/proxmox.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/inventory/proxmox.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
I'm not sure if related to this issue, but I'm not able to make the proxmox inventory plugin work correctly after following the example:

``` 
[WARNING]:  * Failed to parse my.proxmox.yml with auto plugin: 'template'
[WARNING]:  * Failed to parse my.proxmox.yml with yaml plugin: Plugin configuration YAML file, not YAML inventory
[WARNING]:  * Failed to parse my.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 my.proxmox.yml with ansible_collections.community.general.plugins.inventory.proxmox plugin: 'template'
[WARNING]: Unable to parse my.proxmox.yml as an inventory source
```

my.proxmox.yml:
```
plugin: community.general.proxmox
validate_certs: 'yes'
want_facts: 'yes'
url: https://proxmox_host:8006
user: ansible@pve
password: <REDACTED>
keyed_groups:
 - key: proxmox_tags_parsed
   separator: ""
   prefix: group
groups:
  webservers: "'web' in (proxmox_tags_parsed|list)"
  mailservers: "'mail' in (proxmox_tags_parsed|list)"
compose:
  ansible_port: 22
```

Versions:

ansible [core 2.11.3] 
  python version = 3.9.5 (default, May 11 2021, 08:20:37) [GCC 10.3.0]
  jinja version = 3.0.1
  libyaml = True

community.general:3.4.0
Hit this issue as well

Line 302
`if config == 'agent' and int(value.split(',')[0]):`

Is tripping up because proxmox agent is only report a '1' for enabled agent

Reference

https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/qemu/{vmid}/config

Code is tripping on not having ',' in the string

I threw this in for a quick fix

```
if config == 'agent' and isinstance(value ,str):
    if value == '1':
        pass
    elif ',' in value:
        if int(value.split(',')[0]):
            pass
        else:
            continue
    else:
        continue
    agent_iface_key = self.to_safe('%s%s' % (key, "_interfaces"))
    agent_iface_value = self._get_agent_network_interfaces(node, vmid, vmtype)
    if agent_iface_value:
        self.inventory.set_variable(name, agent_iface_key, agent_iface_value)
```

Versions:
ansible-inventory [core 2.11.3]
python version = 3.9.5 (default, Aug 11 2021, 02:58:32) [GCC 11.1.0]
jinja version = 2.11.3
community.general:3.5.0
Proxmox 7.0

These are three separate issues:
1. The original issue is a valid docs request as the constructible options do rely on `want_facts` being enabled.
2. The second issue is likely because the plugin is not enabled.
Add a line like the following to your `ansible.cfg` and try again: (See [here](https://docs.ansible.com/ansible/latest/plugins/inventory.html#id2) for more info)
```ini
[inventory]
 enable_plugins = community.general.proxmox
 ```
 3. The latest issue needs more info as to the actual error received. The suggested solution doesn't seem quite right however given Python's `str.split()` method.
 ```python
no_comma = '1'
with_comma = '1,'
assert int(no_comma.split(',')[0]) == int(with_comma.split(',')[0])
```
 

Resolving patch:
diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py
--- a/plugins/inventory/proxmox.py
+++ b/plugins/inventory/proxmox.py
@@ -81,13 +81,24 @@
 '''
 
 EXAMPLES = '''
+# Minimal example which will not gather additional facts for QEMU/LXC guests
+# By not specifying a URL the plugin will attempt to connect to the controller host on port 8006
 # my.proxmox.yml
 plugin: community.general.proxmox
-url: http://localhost:8006
 user: ansible@pve
 password: secure
-validate_certs: no
+
+# More complete example demonstrating the use of 'want_facts' and the constructed options
+# Note that using facts returned by 'want_facts' in constructed options requires 'want_facts=true'
+# my.proxmox.yml
+plugin: community.general.proxmox
+url: http://pve.domain.com:8006
+user: ansible@pve
+password: secure
+validate_certs: false
+want_facts: true
 keyed_groups:
+    # proxmox_tags_parsed is an example of a fact only returned when 'want_facts=true'
   - key: proxmox_tags_parsed
     separator: ""
     prefix: group


Test patch: