community.vmware
community.vmware copied to clipboard
Can't enable vmtools timesync
SUMMARY
When attempting to set the tools.timeSync value for enabling vmware tools time synchronization changes are never actually made When using the vmware_guest module placing the configuration in advanced_settings makes no change:
advanced_settings:
- key: tools.syncTime
value: 'TRUE'
I've also tried adding it under customvalue, which causes the task to fail from an unknown key
ISSUE TYPE
- Bug Report
COMPONENT NAME
community.vmware.vmware_guest
ANSIBLE VERSION
ansible [core 2.12.1]
config file = None
configured module search path = ['/home/pcte_admin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
ansible collection location = /home/pcte_admin/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0]
jinja version = 2.10.1
libyaml = True
COLLECTION VERSION
Collection Version
---------------- -------
community.vmware 1.17.0
# /usr/local/lib/python3.8/dist-packages/ansible_collections
Collection Version
---------------- -------
community.vmware 1.17.0
CONFIGURATION
OS / ENVIRONMENT
Kubernetes 1.20
STEPS TO REPRODUCE
- name: Adjust resources
community.vmware.vmware_guest:
hostname: "{{ VMWARE_HOST }}"
username: "{{ VMWARE_USER }}"
password: "{{ VMWARE_PASSWORD }}"
validate_certs: False
folder: "{{ vc_datacenter }}/vm/{{ folder }}"
cluster: "{{ vc_cluster }}"
datacenter: "{{ vc_datacenter }}"
name: "{{ vm_prefix.stdout }}-{{ control_machine }}-{{ item.item | string }}"
state: "present"
hardware:
memory_mb: "{{ control_memory }}"
num_cpus: "{{ control_cpu }}"
advanced_settings:
- key: tools.syncTime
value: 'TRUE'
disk:
- size_gb: 50
EXPECTED RESULTS
vmtools timesync gets enabled
ACTUAL RESULTS
vmtools time sync remains disabled
Files identified in the description: None
If these files are inaccurate, please update the component name
section of the description or use the !component
bot command.
Does the module report a change that doesn't happen, or doesn't it even do that and report that everything's OK?
It shows it in the invocation, and the task completes fine, but it doesn't actually get set on the vm.
Is this some kind of "magic" or "protected" setting? I can neither see nor set it through the UI (vCenter 7.0.3d). The same with PowerCLI:
PS C:\Users\mario> $vm = Get-VM -Name "synctest"
PS C:\Users\mario> Get-AdvancedSetting -Entity $vm -Name "tools.syncTime"
PS C:\Users\mario> New-AdvancedSetting -Entity $vm -Name "tools.syncTime" -Value "TRUE" -Confirm:$false -Force:$true
Name Value Type Description
---- ----- ---- -----------
tools.syncTime TRUE VM
PS C:\Users\mario> New-AdvancedSetting -Entity $vm -Name "tools.syncTime" -Value $true -Confirm:$false -Force:$true
Name Value Type Description
---- ----- ---- -----------
tools.syncTime True VM
PS C:\Users\mario> New-AdvancedSetting -Entity $vm -Name "tools.syncTime" -Value 1 -Confirm:$false -Force:$true
Name Value Type Description
---- ----- ---- -----------
tools.syncTime 1 VM
PS C:\Users\mario> New-AdvancedSetting -Entity $vm -Name "tools.syncTime" -Value "1" -Confirm:$false -Force:$true
Name Value Type Description
---- ----- ---- -----------
tools.syncTime 1 VM
PS C:\Users\mario>
I always see a task in vCenter that completes just fine, but the time synchronization isn't changed at all. So I think this isn't really a problem of the vmware_guest
module, you just can't configure this advanced setting directly imho.
Well, reading the description of advanced_settings, IIRC it says that it can set values within the vmx file, which tools.syncTime is located in. That is why I was attempting it through that method
Well, reading the description of advanced_settings, IIRC it says that it can set values within the vmx file, which tools.syncTime is located in. That is why I was attempting it through that method
You're right, advanced_settings should be able to set an advanced setting like tools.syncTime. However, it looks like the vSphere API doesn't allow this. The module can add or change other advanced settings without any problems.
That said, I don't think this is a bug in the module. But I think it's a valid feature request to be able to enable timesync via VMware Tools somehow.
Indeed, it looks like a "magic setting". I don't know how Hashicorp Packer deals with advanced/custom settings, but it has a dedicated config param for timesync in vsphere-iso plugin.
For now, I'm managing to enable timesync using vm_shell:
---
# timesync_action: enable / disable ( default = enable )
- name: Check communication with vmware-tools
community.vmware.vmware_guest_tools_wait:
validate_certs: "{{ vsphere_validate_certs }}"
hostname: "{{ vsphere_hostname }}"
username: "{{ vsphere_username }}"
password: "{{ vsphere_password }}"
datacenter: "{{ vsphere_datacenter }}"
folder: "{{ vsphere_vm_folder }}"
name: "{{ vm_name }}"
delegate_to: localhost
register: tools_wait
until: tools_wait.instance.hw_guest_id is not none
retries: 6
delay: 10
- name: Gather VM info to guess OS
delegate_to: localhost
community.vmware.vmware_guest_info:
validate_certs: "{{ vsphere_validate_certs }}"
hostname: "{{ vsphere_hostname }}"
username: "{{ vsphere_username }}"
password: "{{ vsphere_password }}"
datacenter: "{{ vsphere_datacenter }}"
name: "{{ vm_name }}"
register: local_vm_info
#Assume default is SSH/*nix
- set_fact:
#vm_os: unix
vm_shell: /bin/bash
vm_shell_cwd: /tmp
vm_shell_args: '-c "/usr/bin/vmware-toolbox-cmd timesync {{ timesync_action | default("enable") }}"'
- set_fact:
#vm_os: "{{ local_vm_info.instance.hw_guest_id }}"
vm_shell: C:\Program Files\VMware\VMware Tools\VMwareToolboxCmd.exe
vm_shell_cwd: C:\Windows\Temp
vm_shell_args: "timesync {{ timesync_action | default('enable') }}"
when: local_vm_info.instance.hw_guest_id|lower|regex_search('^windows')
- name: Run timesync command inside the virtual machine
delegate_to: localhost
community.vmware.vmware_vm_shell:
validate_certs: "{{ vsphere_validate_certs }}"
hostname: "{{ vsphere_hostname }}"
username: "{{ vsphere_username }}"
password: "{{ vsphere_password }}"
datacenter: "{{ vsphere_datacenter }}"
folder: "{{ vsphere_vm_folder }}"
vm_id: "{{ vm_name }}"
vm_username: "{{ winrm_ansible_user }}"
vm_password: "{{ winrm_ansible_password }}"
vm_shell: "{{ vm_shell }}"
vm_shell_args: "{{ vm_shell_args }}"
vm_shell_cwd: "{{ vm_shell_cwd }}"
wait_for_process: true
register: vm_shell_synctime_result
I don't think we should implement this in vmware_guest
, the module is already far too complicated.
Maybe a new module vmware_tools_config
? We could start with implementing syncTimeWithHost
and syncTimeWithHostAllowed
, but could also add other settings from ToolsConfigInfo there when the need arises.
cc @ihumster @max-carnage