From 8f89d1d3dae38db8273dd7a45b9320c03e347fa9 Mon Sep 17 00:00:00 2001 From: Klaus Frank Date: Mon, 27 May 2019 07:40:49 +0200 Subject: [PATCH] VMware: Fix python 3 incompatibility (#54123) Add Python2 and Python3 compatible `string.translate` for hostname customzation. Fixes: #54118 --- lib/ansible/modules/cloud/vmware/vmware_guest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py index a53228000dd..1aa5bc055f1 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -1593,7 +1593,8 @@ class PyVmomiHelper(PyVmomi): # Setting hostName, orgName and fullName is mandatory, so we set some default when missing ident.userData.computerName = vim.vm.customization.FixedName() # computer name will be truncated to 15 characters if using VM name - default_name = self.params['name'].translate(None, string.punctuation) + default_name = self.params['name'].replace(' ', '') + default_name = ''.join([c for c in default_name if c not in 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'))