-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aws_collection_constants SUMMARY Adds a simple lookup plugin to retrieve some of the constants in the collection ISSUE TYPE New Module Pull Request COMPONENT NAME plugins/lookup/aws_collection_constants.py ADDITIONAL INFORMATION This means we've one less place we need to update when bumping the supported botocore version. Reviewed-by: Bikouo Aubin <None> Reviewed-by: Mark Chappell <None> Reviewed-by: Alina Buzachis <None>
- Loading branch information
Showing
8 changed files
with
136 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
trivial: | ||
- Update integration tests to use lookup plugin when pulling the default AWS SDK versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# (c) 2023 Ansible Project | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
DOCUMENTATION = ''' | ||
name: aws_collection_constants | ||
author: | ||
- Mark Chappell (@tremble) | ||
short_description: expose various collection related constants | ||
version_added: 6.0.0 | ||
description: | ||
- Exposes various collection related constants for use in integration tests. | ||
options: | ||
_terms: | ||
description: Name of the constant. | ||
choices: | ||
- MINIMUM_BOTOCORE_VERSION | ||
- MINIMUM_BOTO3_VERSION | ||
- HAS_BOTO3 | ||
- AMAZON_AWS_COLLECTION_VERSION | ||
- AMAZON_AWS_COLLECTION_NAME | ||
- COMMUNITY_AWS_COLLECTION_VERSION | ||
- COMMUNITY_AWS_COLLECTION_NAME | ||
required: True | ||
''' | ||
|
||
EXAMPLES = """ | ||
""" | ||
|
||
RETURN = """ | ||
_raw: | ||
description: value | ||
type: str | ||
""" | ||
|
||
from ansible.errors import AnsibleLookupError | ||
from ansible.plugins.lookup import LookupBase | ||
|
||
import ansible_collections.amazon.aws.plugins.module_utils.botocore as botocore_utils | ||
import ansible_collections.amazon.aws.plugins.module_utils.common as common_utils | ||
|
||
try: | ||
import ansible_collections.community.aws.plugins.module_utils.common as community_utils | ||
HAS_COMMUNITY = True | ||
except ImportError: | ||
HAS_COMMUNITY = False | ||
|
||
|
||
class LookupModule(LookupBase): | ||
def lookup_constant(self, name): | ||
if name == 'MINIMUM_BOTOCORE_VERSION': | ||
return botocore_utils.MINIMUM_BOTOCORE_VERSION | ||
if name == 'MINIMUM_BOTO3_VERSION': | ||
return botocore_utils.MINIMUM_BOTO3_VERSION | ||
if name == 'HAS_BOTO3': | ||
return botocore_utils.HAS_BOTO3 | ||
|
||
if name == 'AMAZON_AWS_COLLECTION_VERSION': | ||
return common_utils.AMAZON_AWS_COLLECTION_VERSION | ||
if name == 'AMAZON_AWS_COLLECTION_NAME': | ||
return common_utils.AMAZON_AWS_COLLECTION_NAME | ||
|
||
if name == 'COMMUNITY_AWS_COLLECTION_VERSION': | ||
if not HAS_COMMUNITY: | ||
raise AnsibleLookupError( | ||
'Unable to load ansible_collections.community.aws.plugins.module_utils.common') | ||
return community_utils.COMMUNITY_AWS_COLLECTION_VERSION | ||
if name == 'COMMUNITY_AWS_COLLECTION_NAME': | ||
if not HAS_COMMUNITY: | ||
raise AnsibleLookupError( | ||
'Unable to load ansible_collections.community.aws.plugins.module_utils.common') | ||
return community_utils.COMMUNITY_AWS_COLLECTION_NAME | ||
|
||
def run(self, terms, variables, **kwargs): | ||
self.set_options(var_options=variables, direct=kwargs) | ||
if not terms: | ||
raise AnsibleLookupError("Constant name not provided") | ||
if len(terms) > 1: | ||
raise AnsibleLookupError("Multiple constant names provided") | ||
name = terms[0].upper() | ||
|
||
return [self.lookup_constant(name)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
tests/integration/targets/lookup_aws_collection_constants/aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cloud/aws |
1 change: 1 addition & 0 deletions
1
tests/integration/targets/lookup_aws_collection_constants/meta/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dependencies: [] |
47 changes: 47 additions & 0 deletions
47
tests/integration/targets/lookup_aws_collection_constants/tasks/main.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
- name: 'MINIMUM_BOTOCORE_VERSION' | ||
set_fact: | ||
MINIMUM_BOTOCORE_VERSION: "{{ lookup('amazon.aws.aws_collection_constants', 'MINIMUM_BOTOCORE_VERSION') }}" | ||
|
||
- assert: | ||
that: | ||
- MINIMUM_BOTOCORE_VERSION.startswith("1.") | ||
|
||
- name: 'MINIMUM_BOTO3_VERSION' | ||
set_fact: | ||
MINIMUM_BOTO3_VERSION: "{{ lookup('amazon.aws.aws_collection_constants', 'MINIMUM_BOTO3_VERSION') }}" | ||
|
||
- assert: | ||
that: | ||
- MINIMUM_BOTO3_VERSION.startswith("1.") | ||
|
||
- name: 'HAS_BOTO3' | ||
set_fact: | ||
HAS_BOTO3: "{{ lookup('amazon.aws.aws_collection_constants', 'HAS_BOTO3') }}" | ||
|
||
- assert: | ||
that: | ||
- HAS_BOTO3 | bool | ||
|
||
- name: 'AMAZON_AWS_COLLECTION_VERSION' | ||
set_fact: | ||
AMAZON_AWS_COLLECTION_VERSION: "{{ lookup('amazon.aws.aws_collection_constants', 'AMAZON_AWS_COLLECTION_VERSION') }}" | ||
|
||
- name: 'AMAZON_AWS_COLLECTION_NAME' | ||
set_fact: | ||
AMAZON_AWS_COLLECTION_NAME: "{{ lookup('amazon.aws.aws_collection_constants', 'AMAZON_AWS_COLLECTION_NAME') }}" | ||
|
||
- assert: | ||
that: | ||
- AMAZON_AWS_COLLECTION_NAME == "amazon.aws" | ||
|
||
- name: 'COMMUNITY_AWS_COLLECTION_VERSION' | ||
set_fact: | ||
COMMUNITY_AWS_COLLECTION_VERSION: "{{ lookup('amazon.aws.aws_collection_constants', 'COMMUNITY_AWS_COLLECTION_VERSION') }}" | ||
|
||
- name: 'COMMUNITY_AWS_COLLECTION_NAME' | ||
set_fact: | ||
COMMUNITY_AWS_COLLECTION_NAME: "{{ lookup('amazon.aws.aws_collection_constants', 'COMMUNITY_AWS_COLLECTION_NAME') }}" | ||
|
||
- assert: | ||
that: | ||
- COMMUNITY_AWS_COLLECTION_NAME == "community.aws" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
dependencies: | ||
- role: setup_botocore_pip | ||
dependencies: [] |
4 changes: 2 additions & 2 deletions
4
tests/integration/targets/setup_botocore_pip/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
default_botocore_version: '1.21.0' | ||
default_boto3_version: '1.18.0' | ||
default_botocore_version: "{{ lookup('amazon.aws.aws_collection_constants', 'MINIMUM_BOTOCORE_VERSION') }}" | ||
default_boto3_version: "{{ lookup('amazon.aws.aws_collection_constants', 'MINIMUM_BOTO3_VERSION') }}" |