diff --git a/changelogs/fragments/2967-proxmox_inventory-offline-node-fix.yml b/changelogs/fragments/2967-proxmox_inventory-offline-node-fix.yml new file mode 100644 index 0000000000..d52fef4d8a --- /dev/null +++ b/changelogs/fragments/2967-proxmox_inventory-offline-node-fix.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - proxmox inventory plugin - fixed parsing failures when some cluster nodes are offline (https://github.com/ansible-collections/community.general/issues/2931). diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index 44b807f230..92a1ad4997 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -353,6 +353,9 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): if node['type'] == 'node': self.inventory.add_child(nodes_group, node['node']) + if node['status'] == 'offline': + continue + # get node IP address ip = self._get_node_ip(node['node']) self.inventory.set_variable(node['node'], 'ansible_host', ip) diff --git a/tests/unit/plugins/inventory/test_proxmox.py b/tests/unit/plugins/inventory/test_proxmox.py index a68203b725..7a3b62ccda 100644 --- a/tests/unit/plugins/inventory/test_proxmox.py +++ b/tests/unit/plugins/inventory/test_proxmox.py @@ -9,7 +9,6 @@ __metaclass__ = type import pytest -from ansible.errors import AnsibleError, AnsibleParserError from ansible.inventory.data import InventoryData from ansible_collections.community.general.plugins.inventory.proxmox import InventoryModule @@ -46,7 +45,12 @@ def get_json(url): "disk": 1000, "maxmem": 1000, "uptime": 10000, - "level": ""}] + "level": ""}, + {"type": "node", + "node": "testnode2", + "id": "node/testnode2", + "status": "offline", + "ssl_fingerprint": "yy"}] elif url == "https://localhost:8006/api2/json/pools": # _get_pools return [{"poolid": "test"}] @@ -315,7 +319,6 @@ def test_populate(inventory, mocker): host_qemu = inventory.inventory.get_host('test-qemu') host_qemu_template = inventory.inventory.get_host('test-qemu-template') host_lxc = inventory.inventory.get_host('test-lxc') - host_node = inventory.inventory.get_host('testnode') # check if qemu-test is in the proxmox_pool_test group assert 'proxmox_pool_test' in inventory.inventory.groups @@ -331,3 +334,6 @@ def test_populate(inventory, mocker): # check if qemu template is not present assert host_qemu_template is None + + # check that offline node is in inventory + assert inventory.inventory.get_host('testnode2')