diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py index 3879db6d85e080..e47f341d04ac31 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -1603,8 +1603,9 @@ def customize_vm(self, vm_obj): # Setting hostName, orgName and fullName is mandatory, so we set some default when missing ident.userData.computerName = vim.vm.customization.FixedName() + # Strips punctuation from string in a Python2 and Python3 compatible way + default_name = re.sub(r'[^\w\s]', '', self.params['name']) # computer name will be truncated to 15 characters if using VM name - default_name = self.params['name'].translate(None, string.punctuation) ident.userData.computerName.name = str(self.params['customization'].get('hostname', default_name[0:15])) ident.userData.fullName = str(self.params['customization'].get('fullname', 'Administrator')) ident.userData.orgName = str(self.params['customization'].get('orgname', 'ACME'))