From 91a6f161ade7ab7dd6f7268d9f95bd9bb8a81680 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 28 Oct 2022 10:12:06 -0400 Subject: [PATCH 1/5] remove redundant templar is already in base class env var is already consulted in via config resolution --- plugins/inventory/linode.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/plugins/inventory/linode.py b/plugins/inventory/linode.py index 8790da70793..fe87605bf07 100644 --- a/plugins/inventory/linode.py +++ b/plugins/inventory/linode.py @@ -145,22 +145,14 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): def _build_client(self, loader): """Build the Linode client.""" - t = Templar(loader=loader) - access_token = self.get_option('access_token') - if t.is_template(access_token): - access_token = t.template(variable=access_token, disable_lookups=False) - - if access_token is None: - try: - access_token = os.environ['LINODE_ACCESS_TOKEN'] - except KeyError: - pass + if self.templar.is_template(access_token): + access_token = self.templar.template(variable=access_token, disable_lookups=False) if access_token is None: raise AnsibleError(( 'Could not retrieve Linode access token ' - 'from plugin configuration or environment' + 'from plugin configuration sources' )) self.client = LinodeClient(access_token) From 0e7037acfa8e59cc4b26071326229fe43fc3d4da Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 28 Oct 2022 10:26:10 -0400 Subject: [PATCH 2/5] more whites --- plugins/inventory/linode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inventory/linode.py b/plugins/inventory/linode.py index fe87605bf07..66cb0f25ea4 100644 --- a/plugins/inventory/linode.py +++ b/plugins/inventory/linode.py @@ -147,7 +147,7 @@ def _build_client(self, loader): access_token = self.get_option('access_token') if self.templar.is_template(access_token): - access_token = self.templar.template(variable=access_token, disable_lookups=False) + access_token = self.templar.template(variable=access_token, disable_lookups=False) if access_token is None: raise AnsibleError(( From ee00a8a92311f73d20a78f84c7d37943aa067259 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 28 Oct 2022 10:30:48 -0400 Subject: [PATCH 3/5] no need to import templar again --- plugins/inventory/linode.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/inventory/linode.py b/plugins/inventory/linode.py index 66cb0f25ea4..ea87a9a58ee 100644 --- a/plugins/inventory/linode.py +++ b/plugins/inventory/linode.py @@ -126,7 +126,6 @@ from ansible.errors import AnsibleError, AnsibleParserError from ansible.module_utils.six import string_types from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable -from ansible.template import Templar try: From 0546131d8c6f65fa3a68ecdb9abbced7d32a80c6 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sat, 29 Oct 2022 09:57:55 +0200 Subject: [PATCH 4/5] Add changelog fragment. --- changelogs/fragments/5438-linode.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/5438-linode.yml diff --git a/changelogs/fragments/5438-linode.yml b/changelogs/fragments/5438-linode.yml new file mode 100644 index 00000000000..ce2aeadcf38 --- /dev/null +++ b/changelogs/fragments/5438-linode.yml @@ -0,0 +1,2 @@ +minor_changes: + - "linode inventory plugin - simplify option handling (https://github.com/ansible-collections/community.general/pull/5438)." From cb3d59933332e0bfc96e5be72f794f4562559ab9 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sat, 29 Oct 2022 10:02:00 +0200 Subject: [PATCH 5/5] Try to update tests. --- tests/unit/plugins/inventory/test_linode.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/unit/plugins/inventory/test_linode.py b/tests/unit/plugins/inventory/test_linode.py index 60b3c8cb685..4e6a0188501 100644 --- a/tests/unit/plugins/inventory/test_linode.py +++ b/tests/unit/plugins/inventory/test_linode.py @@ -18,12 +18,15 @@ from ansible.errors import AnsibleError, AnsibleParserError from ansible.parsing.dataloader import DataLoader +from ansible.template import Templar from ansible_collections.community.general.plugins.inventory.linode import InventoryModule @pytest.fixture(scope="module") def inventory(): - return InventoryModule() + plugin = InventoryModule() + plugin.templar = Templar(loader=DataLoader()) + return plugin def test_missing_access_token_lookup(inventory):