diff --git a/changelogs/fragments/54494-ec2-user-data.yaml b/changelogs/fragments/54494-ec2-user-data.yaml new file mode 100644 index 00000000000..d771f9dafd0 --- /dev/null +++ b/changelogs/fragments/54494-ec2-user-data.yaml @@ -0,0 +1,3 @@ +bugfixes: + - ec2 - Only use user_data if the user has specified a value. + This prevents setting the instance's user data to b'None'. diff --git a/lib/ansible/modules/cloud/amazon/ec2.py b/lib/ansible/modules/cloud/amazon/ec2.py index 2a59b7e5c1c..555c436d51d 100644 --- a/lib/ansible/modules/cloud/amazon/ec2.py +++ b/lib/ansible/modules/cloud/amazon/ec2.py @@ -1070,8 +1070,9 @@ def create_instances(module, ec2, vpc, override_count=None): 'placement': zone, 'instance_type': instance_type, 'kernel_id': kernel, - 'ramdisk_id': ramdisk, - 'user_data': to_bytes(user_data, errors='surrogate_or_strict')} + 'ramdisk_id': ramdisk} + if user_data is not None: + params['user_data'] = to_bytes(user_data, errors='surrogate_or_strict') if ebs_optimized: params['ebs_optimized'] = ebs_optimized