ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
808 stars 1.48k forks source link

Linode dynamic inventory plugin fails with ip_style=api due to missing ipv6 pools #8213

Open ashtarcommunications opened 4 months ago

ashtarcommunications commented 4 months ago

Summary

The linode dynamic inventory plugin fails to parse the inventory when ip_style is set to "api", with an error about a missing attribute instance.ips.ipv6.pools

This appears to be due to line 221:

ips += instance.ips.ipv6.pools

I don't see

Issue Type

Bug Report

Component Name

linode

Ansible Version

$ ansible --version
ansible [core 2.15.2]
  python version = 3.11.4 (main, Jun  9 2023, 07:59:55) [GCC 12.3.0] (/usr/bin/python3)
  jinja version = 3.1.2

Community.general Version

$ ansible-galaxy collection list community.general
community.general 7.2.0

Configuration

$ ansible-config dump --only-changed

OS / Environment

Ubuntu 23.04

Steps to Reproduce

plugin: community.general.linode
access_token: "<token>"
ip_style: api

Expected Results

Would expect the inventory plugin to correctly parse the response from the linode API

Actual Results

[WARNING]:  * Failed to parse linode.yml with ansible_collections.community.general.plugins.inventory.linode plugin:
'MappedObject' object has no attribute 'pools'
  File "/home/ansible/.local/lib/python3.11/site-packages/ansible/inventory/manager.py", line 293, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/home/ansible/.local/lib/python3.11/site-packages/ansible_collections/community/general/plugins/inventory/linode.py", line 313, in parse
    self.populate()
  File "/home/ansible/.local/lib/python3.11/site-packages/ansible_collections/community/general/plugins/inventory/linode.py", line 255, in populate
    self._add_hostvars_for_instances()
  File "/home/ansible/.local/lib/python3.11/site-packages/ansible_collections/community/general/plugins/inventory/linode.py", line 220, in _add_hostvars_for_instances
    ips += instance.ips.ipv6.pools

Code of Conduct

ansibullbot commented 4 months ago

Files identified in the description:

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

click here for bot help

ansibullbot commented 4 months ago

cc @Charliekenney23 @InTheCloudDan @LBGarber @decentral1se @displague @rmcintosh click here for bot help

felixfontein commented 4 months ago

It looks like pools was renamed to ranges in https://github.com/linode/linode_api4-python/commit/dc592c706518abc1c6d4b4c88b074970e5375d5f. This was introduced in version 5.4.1: https://github.com/linode/linode_api4-python/releases/tag/v5.4.1

(I really wonder what kind of versioning scheme they use? Breaking changes in a patch version doesn't sound like a good idea to me... Also the PR doesn't mention any kind of motivation for the rename, which doesn't make it any better...)

felixfontein commented 4 months ago

I created a PR to fix this, could you please test it? https://github.com/ansible-collections/community.general/pull/8248

(I have no way to test this.)

ashtarcommunications commented 4 months ago

I get: 'IPv6Range' object has no attribute 'type' and the inventory fails to parse

felixfontein commented 4 months ago

Can you paste the full stack trace? Thanks.

ashtarcommunications commented 4 months ago
Failed to parse linode.yml with ansible_collections.community.general.plugins.inventory.linode plugin:
'IPv6Range' object has no attribute 'type'
  File "/home/<user>/.local/lib/python3.11/site-packages/ansible/inventory/manager.py", line 293, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/home/<user>/.ansible/collections/ansible_collections/community/general/plugins/inventory/linode.py", line 334, in parse
    self.populate()
  File "/home/<user>/.ansible/collections/ansible_collections/community/general/plugins/inventory/linode.py", line 262, in populate
    self._add_hostvars_for_instances()
  File "/home/<user>/.ansible/collections/ansible_collections/community/general/plugins/inventory/linode.py", line 229, in _add_hostvars_for_instances
    for ip_type in set(ip.type for ip in ips):
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/<user>/.ansible/collections/ansible_collections/community/general/plugins/inventory/linode.py", line 229, in <genexpr>
    for ip_type in set(ip.type for ip in ips):
                       ^^^^^^^
  File "/home/<user>/.local/lib/python3.11/site-packages/linode_api4/objects/base.py", line 227, in __getattribute__
    return object.__getattribute__(self, name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
felixfontein commented 3 months ago

I guess in that case further things have changed in a backwards incompatible way. It's probably best if someone who can actually run the plugin against the real service continues debugging and fixing this.