Vsphere_copy module is not idempotent?

vsphere_copy module is not idempotent?

If run the below code, it uploads ISO every time i re-run the playbook. Is this expected behavior

---
- name: create a folder on datastore to upload iso
  hosts: localhost
  gather_facts: false
  pre_tasks:
    - include_vars: vm_vars.yaml
  tasks:
    - name: create a directory
      community.vmware.vsphere_file:
        hostname: "{{ vc_name }}"
        username: "{{ vc_usr_name }}"
        password: "{{ vc_passwd }}"
        validate_certs: false
        datacenter: "{{ dc_name }}"
        datastore: "{{ ds_name }}"
        path: "{{ ds_fldp }}"
        state: directory
      register: folder_status
      delegate_to: localhost
    - name: upload a ISO to "{{ ds_fldp }}"
      community.vmware.vsphere_copy:
        hostname: "{{ vc_name }}"
        username: "{{ vc_usr_name }}"
        password: "{{ vc_passwd }}"
        validate_certs: false
        src: "ubuntu.iso"
        datacenter: "{{ dc_name }}"
        datastore: "{{ ds_name }}"
        path: "ISO/ubuntu.iso"
        timeout: 300
      delegate_to: localhost

is Datacenter a required attribute here?

This might be the expected behavior.

I mean, what do you expect? That there exists an ISO with this name, or that it is exactly the ISO you want to upload? If you just expect a file with the same name the module wouldn’t really do its job. Otherwise, the module would have to download the ISO to compare it with your ISO. Just blindly uploading it seems cheaper. Additionally, it avoids the problem of not having enough free disk space to download the ISO.

is Datacenter a required attribute here?

It looks like it’s required for vsphere_file but not for vsphere_copy. Don’t ask me why :person_shrugging:

That there exists an ISO with this name, or that it is exactly the ISO you want to upload?

Sorry my initial message was not clear. Ja, i want to avoid the same ISO being uploaded unless it is changed.

Hi,

Not very elegant but you could always check your file existence on remote datastore using vsphere_file prior, then add a condition on your copy task to only run it if file is not found.