community.vmware icon indicating copy to clipboard operation
community.vmware copied to clipboard

community.vmware.vmware_guest shows changed in check mode

Open bofillj opened this issue 3 years ago • 5 comments

SUMMARY

When changing powerstate and creating a VM on ESXI, the module shows changed on check mode

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.vmware.vmware_guest

ANSIBLE VERSION
ansible [core 2.11.5] 
  python version = 3.8.6 (default, Jan 22 2021, 11:41:28) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
  jinja version = 3.0.2
  libyaml = True
COLLECTION VERSION
ansible-galaxy collection list community.vmware
# /usr/share/ansible/collections/ansible_collections
Collection       Version
---------------- -------
community.vmware 1.15.0 
CONFIGURATION
ANSIBLE_PIPELINING(/playbooks/ansible.cfg) = True
BECOME_ALLOW_SAME_USER(/playbooks/ansible.cfg) = True
BECOME_PLUGIN_PATH(/playbooks/ansible.cfg) = ['/playbooks/collections/ansible_collections/utils/plugins/become', '/usr/share/ansible/co>
CALLBACKS_ENABLED(/playbooks/ansible.cfg) = ['utils.log', 'utils.profile_tasks_custom']
DEFAULT_ACTION_PLUGIN_PATH(/playbooks/ansible.cfg) = ['/playbooks/collections/ansible_collections/utils/plugins/action', '/usr/share/an>
DEFAULT_FILTER_PLUGIN_PATH(/playbooks/ansible.cfg) = ['/playbooks/collections/ansible_collections/utils/plugins/filter', '/usr/share/an>
DEFAULT_FORKS(/playbooks/ansible.cfg) = 100
DEFAULT_HOST_LIST(/playbooks/ansible.cfg) = ['/playbooks/inventory.yml']
DEFAULT_LOAD_CALLBACK_PLUGINS(/playbooks/ansible.cfg) = True
DEFAULT_LOCAL_TMP(/playbooks/ansible.cfg) = /tmp/.ansible/ansible-local-1610062bwg_4fe
DEFAULT_MODULE_PATH(/playbooks/ansible.cfg) = ['/playbooks/collections/ansible_collections/utils/plugins/modules', '/usr/share/ansible/>
DEFAULT_ROLES_PATH(/playbooks/ansible.cfg) = ['/playbooks/roles', '/usr/share/ansible/roles', '/.ansible/roles', '/usr/sh>
DEFAULT_STDOUT_CALLBACK(/playbooks/ansible.cfg) = utils.yaml_custom
DEFAULT_STRATEGY(/playbooks/ansible.cfg) = free
DEFAULT_TEST_PLUGIN_PATH(/playbooks/ansible.cfg) = ['/playbooks/collections/ansible_collections/utils/plugins/test', '/usr/share/ansibl>
DEFAULT_TIMEOUT(/playbooks/ansible.cfg) = 60
DEFAULT_VAULT_PASSWORD_FILE(/playbooks/ansible.cfg) = /playbooks/key
DIFF_ALWAYS(/playbooks/ansible.cfg) = True
DIFF_CONTEXT(/playbooks/ansible.cfg) = 0
DISPLAY_SKIPPED_HOSTS(/playbooks/ansible.cfg) = False
DUPLICATE_YAML_DICT_KEY(/playbooks/ansible.cfg) = ignore
HOST_KEY_CHECKING(/playbooks/ansible.cfg) = False
INTERPRETER_PYTHON(/playbooks/ansible.cfg) = auto_silent
INVENTORY_CACHE_ENABLED(/playbooks/ansible.cfg) = True
INVENTORY_ENABLED(/playbooks/ansible.cfg) = ['auto', 'host_list', 'script', 'ini', 'yaml']
LOCALHOST_WARNING(/playbooks/ansible.cfg) = False
MAX_FILE_SIZE_FOR_DIFF(/playbooks/ansible.cfg) = 1048576
OS / ENVIRONMENT

RHEL8.4

STEPS TO REPRODUCE

Create an existing VM on ESXI using the module, then run the same code in check mode

# Different task that has same issue
    - name: Apply power state of {{ create_vm_state }} to {{ vm_name }} on {{ esxi_host }}
      community.vmware.vmware_guest:
        datacenter: "{{ esxi_datacenter }}"
        name: "{{ vm_name }}"
        state: "{{ create_vm_state }}"
      delegate_to: localhost
EXPECTED RESULTS

Task shouldn't change in check mode when the VM has already been created previously. Running it outside of check mode doesn't show changed

ACTUAL RESULTS

The task mentioned above change in check mode

<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->
TASK [Create_VM: Apply power state of poweredon to VM on ESXI HOST] ****************************************************************************************************************************
changed: [VM -> localhost]
Tuesday 29 March 2022  14:06:31 +0000 (0:00:03.977)       0:01:40.410 ********* 
Tuesday 29 March 2022  14:06:31 +0000 (0:00:00.062)       0:01:40.473 ********* 

bofillj avatar Mar 29 '22 14:03 bofillj

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.

click here for bot help

ansibullbot avatar Mar 29 '22 14:03 ansibullbot

It looks like the module simply sets changed=True when run in check mode:

https://github.com/ansible-collections/community.vmware/blob/30de1f007ae3d00c8217129eddea66b5a4a7c004/plugins/modules/vmware_guest.py#L3387-L3396

https://github.com/ansible-collections/community.vmware/blob/30de1f007ae3d00c8217129eddea66b5a4a7c004/plugins/modules/vmware_guest.py#L3401-L3408

https://github.com/ansible-collections/community.vmware/blob/30de1f007ae3d00c8217129eddea66b5a4a7c004/plugins/modules/vmware_guest.py#L3410-L3421

https://github.com/ansible-collections/community.vmware/blob/30de1f007ae3d00c8217129eddea66b5a4a7c004/plugins/modules/vmware_guest.py#L3442-L3449

I think that changing this won't be easy.

mariolenz avatar Mar 31 '22 06:03 mariolenz

Usually the paradigm is, right before any actual change is made, module.check_mode is checked, at the lowest granularity for any change.

jnm27 avatar Mar 31 '22 06:03 jnm27

By saying that it won't be easy, does that mean it won't be done?

I agree with the Author that check mode should accurately reflect if it would change or be OK instead of just blindly reporting Changed.

MallocArray avatar Jun 15 '22 13:06 MallocArray

By saying that it won't be easy, does that mean it won't be done?

Not necessarily. But this is a community collection and someone from the community needs to find enough time to invest fixing this. And I don't know when (or if) this will be the case. Actually, I think it might need a major refactoring of the module. Which doesn't make it easier to find enough time to work on this.

I agree with the Author that check mode should accurately reflect if it would change or be OK instead of just blindly reporting Changed.

I fully agree, too. But, as it is, we're short-staffed and additionally... well, see above.

mariolenz avatar Jun 15 '22 15:06 mariolenz

I will try to work this

jnm27 avatar Sep 29 '22 19:09 jnm27

@bofillj @MallocArray

FYI, @jnm27 and me are working on this: #1553

It's still work in progress, but it would be great if you could test this and tell us if it works for you.

One way to get the code from the PR to test would look like this:

mkdir -p  ~/.ansible/collections/ansible_collections/community
git clone https://github.com/ansible-collections/community.vmware ~/.ansible/collections/ansible_collections/community/vmware
cd ~/.ansible/collections/ansible_collections/community/vmware
git fetch origin pull/1553/head:issue1272
git checkout issue1272

mariolenz avatar Dec 08 '22 17:12 mariolenz