From 5f8758d6a3a8c0d86eb9973014f269449ecbc154 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 17 Apr 2018 15:20:09 +0530 Subject: [PATCH] Use correct esxi host variable in vmware_cfg_backup Fixed bug where hostname could not be found and minor documentation changes. (cherry picked from commit 8f5320435f31b2462a36350888ca2833c65cbefc) --- ...38654-update_vmware_cfg_backup_variable_usage.yml | 2 ++ .../modules/cloud/vmware/vmware_cfg_backup.py | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/38654-update_vmware_cfg_backup_variable_usage.yml diff --git a/changelogs/fragments/38654-update_vmware_cfg_backup_variable_usage.yml b/changelogs/fragments/38654-update_vmware_cfg_backup_variable_usage.yml new file mode 100644 index 0000000000..1cf66f6b16 --- /dev/null +++ b/changelogs/fragments/38654-update_vmware_cfg_backup_variable_usage.yml @@ -0,0 +1,2 @@ +bugfixes: +- Changed hostname variable in order for the esxi host to be found when authentication against a vcenter was done. diff --git a/lib/ansible/modules/cloud/vmware/vmware_cfg_backup.py b/lib/ansible/modules/cloud/vmware/vmware_cfg_backup.py index 1e3f30129e..58e965f8f2 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_cfg_backup.py +++ b/lib/ansible/modules/cloud/vmware/vmware_cfg_backup.py @@ -31,7 +31,7 @@ requirements: options: esxi_hostname: description: - - Name of ESXi server. + - Name of ESXi server. This is required only if authentication against a vCenter is done. required: False dest: description: @@ -51,17 +51,17 @@ extends_documentation_fragment: vmware.documentation ''' EXAMPLES = ''' -# save the ESXi configuration locally +# save the ESXi configuration locally by authenticating directly against the ESXi host - name: ESXI backup test local_action: module: vmware_cfg_backup - hostname: esxi_host + hostname: esxi_hostname username: user password: pass state: saved dest: /tmp/ -# save the ESXi configuration locally for specific ESXi +# save the ESXi configuration locally by authenticating against the vCenter and selecting the ESXi host - name: ESXI backup test local_action: module: vmware_cfg_backup @@ -133,7 +133,7 @@ class VMwareConfigurationBackup(PyVmomi): self.module.fail_json(msg="Source file {} does not exist".format(self.src)) url = self.host.configManager.firmwareSystem.QueryFirmwareConfigUploadURL() - url = url.replace('*', self.hostname) + url = url.replace('*', self.host.name) # find manually the url if there is a redirect because urllib2 -per RFC- doesn't do automatic redirects for PUT requests try: request = open_url(url=url, method='HEAD', validate_certs=self.validate_certs) @@ -169,7 +169,7 @@ class VMwareConfigurationBackup(PyVmomi): def save_configuration(self): url = self.host.configManager.firmwareSystem.BackupFirmwareConfiguration() - url = url.replace('*', self.hostname) + url = url.replace('*', self.host.name) if os.path.isdir(self.dest): filename = url.rsplit('/', 1)[1] self.dest = os.path.join(self.dest, filename)