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

Use missing_required_lib more consistently #1152

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
6 changes: 6 additions & 0 deletions changelogs/fragments/1152-missing-botocore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
minor_changes:
- aws_ec2 inventory plugin - use ``missing_required_lib`` for more consistent error message when boto3/botocore is not available (https://github.com/ansible-collections/amazon.aws/pull/1152).
- aws_rds inventory plugin - use ``missing_required_lib`` for more consistent error message when boto3/botocore is not available (https://github.com/ansible-collections/amazon.aws/pull/1152).
- aws_account_attribute lookup plugin - use ``missing_required_lib`` for more consistent error message when boto3/botocore is not available (https://github.com/ansible-collections/amazon.aws/pull/1152).
- aws_secret lookup plugin - use ``missing_required_lib`` for more consistent error message when boto3/botocore is not available (https://github.com/ansible-collections/amazon.aws/pull/1152).
- aws_ssm lookup plugin - use ``missing_required_lib`` for more consistent error message when boto3/botocore is not available (https://github.com/ansible-collections/amazon.aws/pull/1152).
3 changes: 2 additions & 1 deletion plugins/inventory/aws_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@
from ansible.errors import AnsibleError
from ansible.module_utils._text import to_native
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import missing_required_lib
from ansible.plugins.inventory import BaseInventoryPlugin
from ansible.plugins.inventory import Cacheable
from ansible.plugins.inventory import Constructable
Expand Down Expand Up @@ -858,7 +859,7 @@ def parse(self, inventory, loader, path, cache=True):
super(InventoryModule, self).parse(inventory, loader, path)

if not HAS_BOTO3:
raise AnsibleError('The ec2 dynamic inventory plugin requires boto3 and botocore.')
raise AnsibleError(missing_required_lib('botocore and boto3'))

self._read_config_data(path)

Expand Down
3 changes: 2 additions & 1 deletion plugins/inventory/aws_rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@

from ansible.errors import AnsibleError
from ansible.module_utils._text import to_native
from ansible.module_utils.basic import missing_required_lib
from ansible.plugins.inventory import BaseInventoryPlugin
from ansible.plugins.inventory import Cacheable
from ansible.plugins.inventory import Constructable
Expand Down Expand Up @@ -357,7 +358,7 @@ def parse(self, inventory, loader, path, cache=True):
super(InventoryModule, self).parse(inventory, loader, path)

if not HAS_BOTO3:
raise AnsibleError('The RDS dynamic inventory plugin requires boto3 and botocore.')
raise AnsibleError(missing_required_lib('botocore and boto3'))

self._set_credentials()

Expand Down
3 changes: 2 additions & 1 deletion plugins/lookup/aws_account_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

from ansible.errors import AnsibleError
from ansible.module_utils._text import to_native
from ansible.module_utils.basic import missing_required_lib
from ansible.plugins.lookup import LookupBase

from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry
Expand Down Expand Up @@ -99,7 +100,7 @@ class LookupModule(LookupBase):
def run(self, terms, variables, **kwargs):

if not HAS_BOTO3:
raise AnsibleError("The lookup aws_account_attribute requires boto3 and botocore.")
raise AnsibleError(missing_required_lib('botocore and boto3'))

self.set_options(var_options=variables, direct=kwargs)
boto_credentials = _get_credentials(self._options)
Expand Down
3 changes: 2 additions & 1 deletion plugins/lookup/aws_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
from ansible.errors import AnsibleError
from ansible.module_utils.six import string_types
from ansible.module_utils._text import to_native
from ansible.module_utils.basic import missing_required_lib
from ansible.plugins.lookup import LookupBase

from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code
Expand Down Expand Up @@ -177,7 +178,7 @@ def run(self, terms, variables=None, boto_profile=None, aws_profile=None,
:returns: A list of parameter values or a list of dictionaries if bypath=True.
'''
if not HAS_BOTO3:
raise AnsibleError('botocore and boto3 are required for aws_ssm lookup.')
raise AnsibleError(missing_required_lib('botocore and boto3'))

deleted = on_deleted.lower()
if not isinstance(deleted, string_types) or deleted not in ['error', 'warn', 'skip']:
Expand Down
3 changes: 2 additions & 1 deletion plugins/lookup/aws_ssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
from ansible.plugins.lookup import LookupBase
from ansible.utils.display import Display
from ansible.module_utils.six import string_types
from ansible.module_utils.basic import missing_required_lib

from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info
Expand Down Expand Up @@ -170,7 +171,7 @@ def run(self, terms, variables=None, boto_profile=None, aws_profile=None,
'''

if not HAS_BOTO3:
raise AnsibleError('botocore and boto3 are required for aws_ssm lookup.')
raise AnsibleError(missing_required_lib('botocore and boto3'))

# validate arguments 'on_missing' and 'on_denied'
if on_missing is not None and (not isinstance(on_missing, string_types) or on_missing.lower() not in ['error', 'warn', 'skip']):
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __init__(self, **kwargs):
if local_settings["check_boto3"]:
if not HAS_BOTO3:
self._module.fail_json(
msg=missing_required_lib('botocore or boto3'))
msg=missing_required_lib('botocore and boto3'))
if not self.botocore_at_least('1.21.0'):
self.warn('botocore < 1.21.0 is not supported or tested.'
' Some features may not work.')
Expand Down