Make it possible to use boto3_conn outside modules
The `boto3_conn` function requires a module argument, and calls `module.fail_json` if the connection doesn't receive enough arguments. In non-module settings like inventory scripts, there is no module to be passed. The `boto3_inventory_conn` function takes the same arguments except for `module`, and both call _boto3_conn which doesn't require a module be passed.pull/4420/head
parent
7d53fd2ef2
commit
ddf2a73640
|
@ -55,10 +55,19 @@ class AnsibleAWSError(Exception):
|
||||||
|
|
||||||
|
|
||||||
def boto3_conn(module, conn_type=None, resource=None, region=None, endpoint=None, **params):
|
def boto3_conn(module, conn_type=None, resource=None, region=None, endpoint=None, **params):
|
||||||
|
try:
|
||||||
|
return _boto3_conn(conn_type=None, resource=None, region=None, endpoint=None, **params)
|
||||||
|
except ValueError:
|
||||||
|
module.fail_json(msg='There is an issue in the code of the module. You must specify either both, resource or client to the conn_type parameter in the boto3_conn function call')
|
||||||
|
|
||||||
|
def _boto3_conn(conn_type=None, resource=None, region=None, endpoint=None, **params):
|
||||||
profile = params.pop('profile_name', None)
|
profile = params.pop('profile_name', None)
|
||||||
|
|
||||||
if conn_type not in ['both', 'resource', 'client']:
|
if conn_type not in ['both', 'resource', 'client']:
|
||||||
module.fail_json(msg='There is an issue in the code of the module. You must specify either both, resource or client to the conn_type parameter in the boto3_conn function call')
|
raise ValueError('There is an issue in the calling code. You '
|
||||||
|
'must specify either both, resource, or client to '
|
||||||
|
'the conn_type parameter in the boto3_conn function '
|
||||||
|
'call')
|
||||||
|
|
||||||
if conn_type == 'resource':
|
if conn_type == 'resource':
|
||||||
resource = boto3.session.Session(profile_name=profile).resource(resource, region_name=region, endpoint_url=endpoint, **params)
|
resource = boto3.session.Session(profile_name=profile).resource(resource, region_name=region, endpoint_url=endpoint, **params)
|
||||||
|
@ -71,6 +80,7 @@ def boto3_conn(module, conn_type=None, resource=None, region=None, endpoint=None
|
||||||
client = boto3.session.Session(profile_name=profile).client(resource, region_name=region, endpoint_url=endpoint, **params)
|
client = boto3.session.Session(profile_name=profile).client(resource, region_name=region, endpoint_url=endpoint, **params)
|
||||||
return client, resource
|
return client, resource
|
||||||
|
|
||||||
|
boto3_inventory_conn = _boto3_conn
|
||||||
|
|
||||||
def aws_common_argument_spec():
|
def aws_common_argument_spec():
|
||||||
return dict(
|
return dict(
|
||||||
|
|
Loading…
Reference in New Issue