From ba8b5ec0d39d4282e4e748502131926e04396cf2 Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Tue, 9 Apr 2019 15:52:49 -0400 Subject: [PATCH] [ec2] Use user_data if specified (#54494) * Use user_data if specified * changelog --- changelogs/fragments/54494-ec2-user-data.yaml | 3 +++ lib/ansible/modules/cloud/amazon/ec2.py | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/54494-ec2-user-data.yaml 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