{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/13010","labels_url":"https://api.github.com/repos/ansible/ansible/issues/13010/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/13010/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/13010/events","html_url":"https://github.com/ansible/ansible/issues/13010","id":114740781,"number":13010,"title":"AWS boto3 - profile support","user":{"login":"Etherdaemon","id":8214068,"avatar_url":"https://avatars.githubusercontent.com/u/8214068?v=3","gravatar_id":"","url":"https://api.github.com/users/Etherdaemon","html_url":"https://github.com/Etherdaemon","followers_url":"https://api.github.com/users/Etherdaemon/followers","following_url":"https://api.github.com/users/Etherdaemon/following{/other_user}","gists_url":"https://api.github.com/users/Etherdaemon/gists{/gist_id}","starred_url":"https://api.github.com/users/Etherdaemon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Etherdaemon/subscriptions","organizations_url":"https://api.github.com/users/Etherdaemon/orgs","repos_url":"https://api.github.com/users/Etherdaemon/repos","events_url":"https://api.github.com/users/Etherdaemon/events{/privacy}","received_events_url":"https://api.github.com/users/Etherdaemon/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-03T04:44:40Z","updated_at":"2015-11-03T06:37:08Z","closed_at":null,"body":"**Issue Type:**\r\n\r\nBug Report\r\n\r\n\r\n**Ansible Version**\r\nansible 2.0.0 (detached HEAD de54f26376) last updated 2015/11/03 08:46:06 (GMT +1000)\r\n  lib/ansible/modules/core: (detached HEAD e318be30ff) last updated 2015/11/03 08:45:42 (GMT +1000)\r\n  lib/ansible/modules/extras: (detached HEAD 80f198a82f) last updated 2015/11/03 08:45:42 (GMT +1000)\r\n\r\nRunning Ansible from source - v2.0.0-0.4.beta2\r\n\r\n**Environment:**\r\nOSX 10.10.5\r\nRunning Ansible from source - v2.0.0-0.4.beta2\r\nRunning boto (2.38.0) and boto3 (1.1.4)\r\nPython 2.7.10\r\n\r\n**Summary:**\r\n\r\nWhen utilising boto3_conn from module_utils/ec2.py and specifying a boto profile_name, the connection fails due to profile_name not being a valid boto3.session.Session().client() parameter.\r\n\r\n*TypeError: client() got an unexpected keyword argument 'profile_name'*\r\n\r\n**Steps To Reproduce:**\r\n\r\nCreating a new module using boto3 for listing Route53 entries, host zones etc and allowing the user to provide a boto profile - same behaviour as in boto (version 2).\r\n\r\nConnection setup in new module:\r\n\r\n    try:\r\n        region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)\r\n        route53 = boto3_conn(module, conn_type='client', resource='route53', **aws_connect_kwargs)\r\n    except boto.exception.NoAuthHandlerFound, e:\r\n        module.fail_json(msg=\"Can't authorize connection - \"+str(e))\r\n\r\nboto3_conn section in question:\r\n\r\n    elif conn_type == 'client':\r\n        client = boto3.session.Session().client(resource, region_name=region, endpoint_url=endpoint, **params)\r\n    return client\r\n\r\nSetup a play using the new module and specify a profile: *name*\r\n\r\n**Expected Results:**\r\n\r\n    TASK [route53_entries : Testing custom module] *********************************\r\n     ok: [127.0.0.1] => {\"HostedZones\": [{ dictionary of returned hosted zones from AWS }}\r\n\r\n**Actual Results:**\r\n\r\n    TASK [route53_entries : Testing custom module] *********************************\r\n    An exception occurred during task execution. The full traceback is:\r\n    Traceback (most recent call last):\r\n      File \"/Users/Etherdaemon/.ansible/tmp/ansible-tmp-1446523327.09-207574321397669/route53_facts\", line 2208, in <module>\r\n    main()\r\n      File \"/Users/Etherdaemon/.ansible/tmp/ansible-tmp-1446523327.09-207574321397669/route53_facts\", line 67, in main\r\n        route53 = boto3_conn(module, conn_type='client', resource='route53', **aws_connect_kwargs)\r\n      File \"/Users/Etherdaemon/.ansible/tmp/ansible-tmp-1446523327.09-207574321397669/route53_facts\", line 2033, in boto3_conn\r\n        client = boto3.session.Session().client(resource, region_name=region, endpoint_url=endpoint, profile_name=profile_name, **params)\r\n    TypeError: client() got an unexpected keyword argument 'profile_name'\r\n\r\n    fatal: [127.0.0.1]: FAILED! => {\"changed\": false, \"failed\": true, \"invocation\": {\"module_args\": {\"profile\": \"personal\", \"type\": \"A\"}, \"module_name\": \"route53_facts\"}, \"parsed\": false}\r\n\r\n\r\n**Proposed fix:**\r\n\r\nMy initial thoughts are to do the following - I've tested this for just my own scenario so obviously a lot more thought has to go in for everyone's use cases.\r\n\r\nUpdate module_utils/ec2.py with the following:\r\n\r\n* method: get_aws_connection_info\r\n  * Remove profile_name from boto_params dictionary for boto3 requests\r\n  * move existing return region, ec2_url, boto_params to be directly underneath the boto/boto3 else statement (to cater for boto 2 connections)\r\n  * add a new return statement under the boto3 if statement to include the new profile_name argument separately - return region, ec2_url, profile_name, boto_params\r\n\r\n* method: boto3_conn\r\n  * add a new profile_name=None input parameter\r\n  * update the boto3.session statement to create the session with the profile and the client with the rest of the arguments.\r\n\r\nThis should then allow users to call the boto3_conn like so...\r\n\r\n    try:\r\n        region, ec2_url, profile_name, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)\r\n        route53 = boto3_conn(module, conn_type='client', resource='route53', profile_name=profile_name, **aws_connect_kwargs)\r\n    except boto.exception.NoAuthHandlerFound, e:\r\n        module.fail_json(msg=\"Can't authorize connection - \"+str(e))\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/153258739","html_url":"https://github.com/ansible/ansible/issues/13010#issuecomment-153258739","issue_url":"https://api.github.com/repos/ansible/ansible/issues/13010","id":153258739,"user":{"login":"Etherdaemon","id":8214068,"avatar_url":"https://avatars.githubusercontent.com/u/8214068?v=3","gravatar_id":"","url":"https://api.github.com/users/Etherdaemon","html_url":"https://github.com/Etherdaemon","followers_url":"https://api.github.com/users/Etherdaemon/followers","following_url":"https://api.github.com/users/Etherdaemon/following{/other_user}","gists_url":"https://api.github.com/users/Etherdaemon/gists{/gist_id}","starred_url":"https://api.github.com/users/Etherdaemon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Etherdaemon/subscriptions","organizations_url":"https://api.github.com/users/Etherdaemon/orgs","repos_url":"https://api.github.com/users/Etherdaemon/repos","events_url":"https://api.github.com/users/Etherdaemon/events{/privacy}","received_events_url":"https://api.github.com/users/Etherdaemon/received_events","type":"User","site_admin":false},"created_at":"2015-11-03T06:37:08Z","updated_at":"2015-11-03T06:37:08Z","body":"@willthames has brought up a good point on the fact that this does change the specification of the reply for existing modules calling the get_aws_connection_info method. It seems a bit hacky but I might update the merge request to return the additonal argument only if a profile_name is passed in. This should then allow boto profiles to be fixed while not affecting the existing setups that people are using."}}