Bkprt py3 ec2 user data (#37664)

* Fix use of user_data field with spot_price in ec2 module (#37628)

The user_data field is base64 encoded inside of the boto library.  In
Python3, base64 must be used with byte strings.  So we make sure to
encode the user_data into a byte string before passing it on to the boto
library.

Fixes #34978

(cherry picked from commit 0d55081ba8)

* Python3 ec2 fix added to changelog
pull/37276/head
Toshio Kuratomi 7 years ago committed by Matt Davis
parent 97a0516cf6
commit 389c4d1536

@ -0,0 +1,2 @@
bugfixes:
- ec2 - Fix ec2 user_data parameter to properly convert to base64 on python3 (https://github.com/ansible/ansible/pull/37628)

@ -620,15 +620,15 @@ EXAMPLES = '''
''' '''
import traceback
import time import time
import traceback
from ast import literal_eval from ast import literal_eval
from ansible.module_utils.six import get_function_code, string_types from distutils.version import LooseVersion
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import get_aws_connection_info, ec2_argument_spec, ec2_connect from ansible.module_utils.ec2 import get_aws_connection_info, ec2_argument_spec, ec2_connect
from distutils.version import LooseVersion from ansible.module_utils.six import get_function_code, string_types
from ansible.module_utils.six import string_types from ansible.module_utils._text import to_bytes, to_text
try: try:
import boto.ec2 import boto.ec2
@ -1121,7 +1121,7 @@ def create_instances(module, ec2, vpc, override_count=None):
'instance_type': instance_type, 'instance_type': instance_type,
'kernel_id': kernel, 'kernel_id': kernel,
'ramdisk_id': ramdisk, 'ramdisk_id': ramdisk,
'user_data': user_data} 'user_data': to_bytes(user_data, errors='surrogate_or_strict')}
if ebs_optimized: if ebs_optimized:
params['ebs_optimized'] = ebs_optimized params['ebs_optimized'] = ebs_optimized

Loading…
Cancel
Save