Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linnode inventory, remove redundant #5438

Merged
merged 5 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/5438-linode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "linode inventory plugin - simplify option handling (https://github.com/ansible-collections/community.general/pull/5438)."
15 changes: 3 additions & 12 deletions plugins/inventory/linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -145,22 +144,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)
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/plugins/inventory/test_linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down