diff --git a/cloud/amazon/_ec2_ami_search.py b/cloud/amazon/_ec2_ami_search.py index 65953af2b5d..4fac97e9471 100644 --- a/cloud/amazon/_ec2_ami_search.py +++ b/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()