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

Allow botocore configuration for aws modules #55217

Merged
merged 7 commits into from
Feb 18, 2020

Conversation

s-hertel
Copy link
Contributor

@s-hertel s-hertel commented Apr 12, 2019

SUMMARY

WIP while still looking at a possible solution for boto modules.

This PR allows UserAgent to be set for boto modules and allows general configuration for boto3 modules. Many boto configurations can be set by a boto config file like connection timeout and proxy settings. UserAgent is not able to be configured in that way. In boto3 most of those options have been removed and are only modifiable via code. This addresses both problems.

Tested with CloudTrail.

Fix #55182

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

AWS modules

Example use:

    - name: create bucket
      aws_s3:
        aws_config:
          user_agent: "{{ custom_user_agent }}"
        bucket: "{{ bucket }}"
        region: us-east-1
        mode: create

@ansibot ansibot added WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers. affects_2.8 This issue/PR affects Ansible v2.8 aws cloud feature This issue/PR relates to a feature request. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Apr 12, 2019
@s-hertel s-hertel changed the title [WIP] Allow botocore configuration to be configurable for boto3 modules Allow botocore configuration for aws modules Apr 12, 2019
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers. core_review In order to be merged, this PR must follow the core review workflow. labels Apr 12, 2019
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Apr 12, 2019
@jillr jillr removed the needs_triage Needs a first human triage before being processed. label Apr 18, 2019
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Apr 25, 2019
Copy link
Contributor

@tremble tremble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking to close out some of the old PRs before the split happens.

The change looks good to me, any reason not ro move this one forward?

user_agent_extra='Ansible/{0}'.format(__version__),
)

if params.get('config') is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where's the config argument come from?

Copy link
Contributor Author

@s-hertel s-hertel Feb 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boto3_conn takes **params, so modules have been able to set custom configurations by doing

boto_core_config = botocore.config.Config(retries={'mode': 'adaptive', 'max_attempts': 10})
connection = boto3_conn(module, conn_type='client', resource=resource, region=region, endpoint=ec2_url, config=boto_core_config, **aws_connect_params)

The old boto config file actually supported a decent amount of customization for different services, whereas botocore/boto3 do not in ~/.aws/config. It makes sense that a module would want to define a resilient default config for the particular service. I'm not sure off the top of my head if there are still things in our codebase using it (though there have been, and easily could be 3rd party things). I don't think it's a super common use case, but the prospect of breaking something in module_utils/ec2 gives me figurative hives.

lib/ansible/plugins/doc_fragments/aws.py Outdated Show resolved Hide resolved
@s-hertel
Copy link
Contributor Author

@tremble I mostly paused on it due to caution and lack of enough reviews. I'll add a changelog too.

@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Feb 17, 2020
@s-hertel
Copy link
Contributor Author

I added ci_complete to the last commit to be on the safe side. I'll merge when they are passing.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. core_review In order to be merged, this PR must follow the core review workflow. and removed core_review In order to be merged, this PR must follow the core review workflow. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Feb 17, 2020
@s-hertel s-hertel merged commit ed6a6ac into ansible:devel Feb 18, 2020
@s-hertel
Copy link
Contributor Author

Thanks @jillr and @tremble for reviewing!

@s-hertel s-hertel deleted the botocore_configuration branch February 25, 2020 22:24
@ansible ansible locked and limited conversation to collaborators Mar 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 aws cloud core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add User-Agent Config for AWS Modules
4 participants