From 8eba30b488ebe64e7110778a9755db49fc1e9e72 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 20 Jul 2015 13:38:37 -0700 Subject: [PATCH] Deprecated _ec2_ami_search now verifies SSL certificates --- .../modules/cloud/amazon/_ec2_ami_search.py | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/_ec2_ami_search.py b/lib/ansible/modules/cloud/amazon/_ec2_ami_search.py index 65953af2b5d..4fac97e9471 100644 --- a/lib/ansible/modules/cloud/amazon/_ec2_ami_search.py +++ b/lib/ansible/modules/cloud/amazon/_ec2_ami_search.py @@ -65,6 +65,15 @@ options: required: false default: paravirtual choices: ["paravirtual", "hvm"] + validate_certs: + description: + - If C(no), SSL certificates will not be validated. This should only + be set to C(no) used on personally controlled sites using self-signed + certificates. Prior to 1.9.3 the code defaulted to C(no). + required: false + default: 'yes' + choices: ['yes', 'no'] + version_added: '1.9.3' author: Lorin Hochstein ''' @@ -102,11 +111,12 @@ AWS_REGIONS = ['ap-northeast-1', def get_url(module, url): """ Get url and return response """ - try: - r = urllib2.urlopen(url) - except (urllib2.HTTPError, urllib2.URLError), e: - code = getattr(e, 'code', -1) - module.fail_json(msg="Request failed: %s" % str(e), status_code=code) + + r, info = fetch_url(module, url) + if info['status'] != 200: + # Backwards compat + info['status_code'] = info['status'] + module.fail_json(**info) return r @@ -182,7 +192,8 @@ def main(): choices=['i386', 'amd64']), region=dict(required=False, default='us-east-1', choices=AWS_REGIONS), virt=dict(required=False, default='paravirtual', - choices=['paravirtual', 'hvm']) + choices=['paravirtual', 'hvm']), + validate_certs = dict(required=False, default=True, type='bool'), ) module = AnsibleModule(argument_spec=arg_spec) distro = module.params['distro'] @@ -196,6 +207,7 @@ def main(): # this is magic, see lib/ansible/module_common.py from ansible.module_utils.basic import * +from ansible.module_utils.urls import * if __name__ == '__main__': main()