diff --git a/changelogs/fragments/8248-linode-rename.yml b/changelogs/fragments/8248-linode-rename.yml new file mode 100644 index 0000000000..507073b0b0 --- /dev/null +++ b/changelogs/fragments/8248-linode-rename.yml @@ -0,0 +1,4 @@ +bugfixes: + - "linode inventory plugin - linode_api4 renamed the IPv6 ``pools`` to ``ranges`` in version 5.4.1. The plugin now checks the package + version to use the appropriate name (https://github.com/ansible-collections/community.general/issues/8213, + https://github.com/ansible-collections/community.general/pull/8248)." diff --git a/plugins/inventory/linode.py b/plugins/inventory/linode.py index 594cf30eba..2284fa7396 100644 --- a/plugins/inventory/linode.py +++ b/plugins/inventory/linode.py @@ -130,10 +130,12 @@ from ansible.errors import AnsibleError from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable from ansible_collections.community.general.plugins.plugin_utils.unsafe import make_unsafe +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion try: from linode_api4 import LinodeClient + from linode_api4.linode_client import package_version from linode_api4.objects.linode import Instance from linode_api4.errors import ApiError as LinodeApiError HAS_LINODE = True @@ -225,7 +227,12 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): if ip_style == 'api': ips = instance.ips.ipv4.public + instance.ips.ipv4.private ips += [instance.ips.ipv6.slaac, instance.ips.ipv6.link_local] - ips += instance.ips.ipv6.pools + # linode_api4 renamed pools to ranges in 5.4.1 (https://github.com/linode/linode_api4-python/releases/tag/v5.4.1, + # https://github.com/linode/linode_api4-python/commit/dc592c706518abc1c6d4b4c88b074970e5375d5f) + if LooseVersion(package_version) < LooseVersion("5.4.1"): + ips += instance.ips.ipv6.pools + else: + ips += instance.ips.ipv6.ranges for ip_type in set(ip.type for ip in ips): self.inventory.set_variable(