mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
linnode inventory, remove redundant (#5438)
* remove redundant templar is already in base class env var is already consulted in via config resolution * more whites * no need to import templar again * Add changelog fragment. * Try to update tests. Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
a1f75efee2
commit
20b84fc709
3 changed files with 9 additions and 13 deletions
2
changelogs/fragments/5438-linode.yml
Normal file
2
changelogs/fragments/5438-linode.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- "linode inventory plugin - simplify option handling (https://github.com/ansible-collections/community.general/pull/5438)."
|
|
@ -126,7 +126,6 @@ import os
|
||||||
from ansible.errors import AnsibleError, AnsibleParserError
|
from ansible.errors import AnsibleError, AnsibleParserError
|
||||||
from ansible.module_utils.six import string_types
|
from ansible.module_utils.six import string_types
|
||||||
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable
|
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable
|
||||||
from ansible.template import Templar
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -145,22 +144,14 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
def _build_client(self, loader):
|
def _build_client(self, loader):
|
||||||
"""Build the Linode client."""
|
"""Build the Linode client."""
|
||||||
|
|
||||||
t = Templar(loader=loader)
|
|
||||||
|
|
||||||
access_token = self.get_option('access_token')
|
access_token = self.get_option('access_token')
|
||||||
if t.is_template(access_token):
|
if self.templar.is_template(access_token):
|
||||||
access_token = t.template(variable=access_token, disable_lookups=False)
|
access_token = self.templar.template(variable=access_token, disable_lookups=False)
|
||||||
|
|
||||||
if access_token is None:
|
|
||||||
try:
|
|
||||||
access_token = os.environ['LINODE_ACCESS_TOKEN']
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if access_token is None:
|
if access_token is None:
|
||||||
raise AnsibleError((
|
raise AnsibleError((
|
||||||
'Could not retrieve Linode access token '
|
'Could not retrieve Linode access token '
|
||||||
'from plugin configuration or environment'
|
'from plugin configuration sources'
|
||||||
))
|
))
|
||||||
|
|
||||||
self.client = LinodeClient(access_token)
|
self.client = LinodeClient(access_token)
|
||||||
|
|
|
@ -18,12 +18,15 @@ mandatory_py_version = pytest.mark.skipif(
|
||||||
|
|
||||||
from ansible.errors import AnsibleError, AnsibleParserError
|
from ansible.errors import AnsibleError, AnsibleParserError
|
||||||
from ansible.parsing.dataloader import DataLoader
|
from ansible.parsing.dataloader import DataLoader
|
||||||
|
from ansible.template import Templar
|
||||||
from ansible_collections.community.general.plugins.inventory.linode import InventoryModule
|
from ansible_collections.community.general.plugins.inventory.linode import InventoryModule
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def inventory():
|
def inventory():
|
||||||
return InventoryModule()
|
plugin = InventoryModule()
|
||||||
|
plugin.templar = Templar(loader=DataLoader())
|
||||||
|
return plugin
|
||||||
|
|
||||||
|
|
||||||
def test_missing_access_token_lookup(inventory):
|
def test_missing_access_token_lookup(inventory):
|
||||||
|
|
Loading…
Reference in a new issue