ansible-collections / community.vmware

Ansible Collection for VMware
GNU General Public License v3.0
351 stars 337 forks source link

Can't modify VM logging settings in .vmx file #1835

Open vmbro opened 1 year ago

vmbro commented 1 year ago
SUMMARY

Can not edit logging = "FALSE" key value as "TRUE" or delete this logging key value in .vmx configuration file with advanced_settings parameter. I would like to edit this parameter as "TRUE" if virtual machine logging disabled. I am able to create/change/delete other keys with same playbook, but I can not change the logging key. There is no error during this change.

COMPONENT NAME

community.vmware.vmware_guest

ADDITIONAL INFORMATION
tasks:
    - name: Enable VM Logging
      community.vmware.vmware_guest:
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        datacenter: "{{ vcenter_datacenter }}"
        validate_certs: "{{ vcenter_validate_certs }}"
        name: "{{ item.name }}"
        state: present
        folder: /LAB
        advanced_settings:
          - key: logging
            value: TRUE
      loop: "{{ virtual_machines }}"
      loop_control:
        loop_var: item
mariolenz commented 1 year ago

I'm not 100% sure about this, but it looks like there are some advanced settings you can't set directly. The vSphere API seems to ignore them. I've seen this already in #1330.

Does the module report a change that doesn't happen, or doesn't it even do that and report that everything's OK? And what do you see in your vCenter? Is there a task that succeeds, but there's no change?

vmbro commented 1 year ago

Yes, module does report this as change and I can see reconfigure virtual machine logs on vCenter. All reconfigure logs are success at vCenter tasks. I agree with you, this is similar as #1330

vmbro commented 1 year ago

I just tested this enabling VM logging with PowerCLI and everything works fine. I can easily change this parameter with following function. $newSpec has EnableLogging flag as $true. It seems vSphere API works fine with PowerCLI.

$vm.ExtensionData.ReconfigVM($newSpec)
ihumster commented 1 year ago

@vmbro $newSpec - what type is this object?

mariolenz commented 1 year ago

I just tested this enabling VM logging with PowerCLI and everything works fine. I can easily change this parameter with following function. $newSpec has EnableLogging flag as $true. It seems vSphere API works fine with PowerCLI.

$vm.ExtensionData.ReconfigVM($newSpec)

I'm not sure if this is the same thing. I mean, you do it by using a flag in the spec and not by setting an advanced setting directly. Even if it is, at the end of the day, an advanced setting there might be differences how the API handles this.

$newSpec - what type is this object?

@ihumster Possibly VirtualMachineConfigSpec, where flags is a VirtualMachineFlagInfo which has enableLogging.

We're already using flags for Virtualization-based security and Intel Virtualization Technology for Directed I/O:

https://github.com/ansible-collections/community.vmware/blob/fd203158eb8d67e4bf218b33fe98fd1afa922072/plugins/modules/vmware_guest.py#L1712-L1726

If it isn't possible to set this advanced setting directly, maybe we need to implement a new parameter for this. Or, alternatively, a new optionflags with a sub-option enable_logging or similar. And, in the long run, possibly move iommu and virt_based_security from hardware there. This might make the module easier to maintain in the long run, especially when the need arises to implement even more flags.

ihumster commented 1 year ago

@mariolenz Just I mean VM Advanced Options and VirtualMachineFlag not the same.