# Vsphere\_copy module is not idempotent?

**URL:** <https://forum.ansible.com/t/vsphere-copy-module-is-not-idempotent/2071>\
**Category:** Get Help\
**Tags:** vmware, collections, ubuntu\
**Created:** [November 1, 2023, 7:57am UTC](https://forum.ansible.com/t/vsphere-copy-module-is-not-idempotent/2071 "2023-11-01T07:57:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ttytsdeur](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@ttytsdeur](https://forum.ansible.com/u/ttytsdeur)\
**Post date:** [November 1, 2023, 7:57am UTC](https://forum.ansible.com/t/vsphere-copy-module-is-not-idempotent/2071/1 "2023-11-01T07:57:44Z")

</div>

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

```auto
---
- 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?

---

<div class="post-metadata">

**Author:** ![mariolenz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mariolenz/32/108_2.png) [@mariolenz](https://forum.ansible.com/u/mariolenz)\
**Post date:** [November 1, 2023, 3:43pm UTC](https://forum.ansible.com/t/vsphere-copy-module-is-not-idempotent/2071/2 "2023-11-01T15:43:23Z")

</div>

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 🤷

---

<div class="post-metadata">

**Author:** ![ttytsdeur](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@ttytsdeur](https://forum.ansible.com/u/ttytsdeur)\
**Post date:** [November 1, 2023, 4:31pm UTC](https://forum.ansible.com/t/vsphere-copy-module-is-not-idempotent/2071/3 "2023-11-01T16:31:44Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![ptn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ptn/32/481_2.png) [@ptn](https://forum.ansible.com/u/ptn)\
**Post date:** [November 1, 2023, 4:56pm UTC](https://forum.ansible.com/t/vsphere-copy-module-is-not-idempotent/2071/4 "2023-11-01T16:56:55Z")

</div>

Hi,

Not very elegant but you could always check your file existence on remote datastore using [vsphere\_file](https://docs.ansible.com/ansible/latest/collections/community/vmware/vsphere_file_module.html#ansible-collections-community-vmware-vsphere-file-module) prior, then add a condition on your copy task to only run it if file is not found.
