1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Make an aws_credentials documentation fragment for plugins using environment vars (#35578)

This commit is contained in:
Sloane Hertel 2018-02-02 08:50:11 -05:00 committed by GitHub
parent 4ec16867fd
commit fd72e4aef2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 38 deletions

View file

@ -11,6 +11,8 @@ version_added: "2.5"
requirements: requirements:
- boto3 - boto3
- botocore - botocore
extends_documentation_fragment:
- aws_credentials
short_description: Look up AWS account attributes. short_description: Look up AWS account attributes.
description: description:
- Describes attributes of your AWS account. You can specify one of the listed - Describes attributes of your AWS account. You can specify one of the listed
@ -27,39 +29,6 @@ options:
- max-elastic-ips - max-elastic-ips
- vpc-max-elastic-ips - vpc-max-elastic-ips
- has-ec2-classic - has-ec2-classic
boto_profile:
description: The boto profile to use to create the connection.
default: null
env:
- name: AWS_PROFILE
- name: AWS_DEFAULT_PROFILE
aws_access_key:
description: The AWS access key to use.
default: null
env:
- name: AWS_ACCESS_KEY_ID
- name: AWS_ACCESS_KEY
- name: EC2_ACCESS_KEY
aws_secret_key:
description: The AWS secret key that corresponds to the access key.
default: null
env:
- name: AWS_SECRET_ACCESS_KEY
- name: AWS_SECRET_KEY
- name: EC2_SECRET_KEY
aws_security_token:
description: The AWS security token if using temporary access and secret keys.
default: null
env:
- name: AWS_SECURITY_TOKEN
- name: AWS_SESSION_TOKEN
- name: EC2_SECURITY_TOKEN
region:
description: The region for which to create the connection.
default: null
env:
- name: AWS_REGION
- name: EC2_REGION
""" """
EXAMPLES = """ EXAMPLES = """
@ -100,10 +69,7 @@ import os
def _boto3_conn(region, credentials): def _boto3_conn(region, credentials):
if 'boto_profile' in credentials: boto_profile = credentials.pop('aws_profile', None)
boto_profile = credentials.pop('boto_profile')
else:
boto_profile = None
try: try:
connection = boto3.session.Session(profile_name=boto_profile).client('ec2', region, **credentials) connection = boto3.session.Session(profile_name=boto_profile).client('ec2', region, **credentials)
@ -120,7 +86,7 @@ def _boto3_conn(region, credentials):
def _get_credentials(options): def _get_credentials(options):
credentials = {} credentials = {}
credentials['boto_profile'] = options['boto_profile'] credentials['aws_profile'] = options['aws_profile']
credentials['aws_secret_access_key'] = options['aws_secret_key'] credentials['aws_secret_access_key'] = options['aws_secret_key']
credentials['aws_access_key_id'] = options['aws_access_key'] credentials['aws_access_key_id'] = options['aws_access_key']
credentials['aws_session_token'] = options['aws_security_token'] credentials['aws_session_token'] = options['aws_security_token']

View file

@ -0,0 +1,39 @@
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
class ModuleDocFragment(object):
# inventory cache
DOCUMENTATION = """
options:
aws_profile:
description: The AWS profile
aliases: ['boto_profile']
env:
- name: AWS_PROFILE
- name: AWS_DEFAULT_PROFILE
aws_access_key:
description: The AWS access key to use.
env:
- name: AWS_ACCESS_KEY_ID
- name: AWS_ACCESS_KEY
- name: EC2_ACCESS_KEY
aws_secret_key:
description: The AWS secret key that corresponds to the access key.
env:
- name: AWS_SECRET_ACCESS_KEY
- name: AWS_SECRET_KEY
- name: EC2_SECRET_KEY
aws_security_token:
description: The AWS security token if using temporary access and secret keys.
env:
- name: AWS_SECURITY_TOKEN
- name: AWS_SESSION_TOKEN
- name: EC2_SECURITY_TOKEN
region:
description: The region for which to create the connection.
env:
- name: AWS_REGION
- name: EC2_REGION
"""