---
- name: Mount NFS (ds1) datastores to ESXi
  vmware_host_datastore:
    hostname: '{{ item }}'
    username: '{{ esxi_user }}'
    password: '{{ esxi_password }}'
    datastore_name: '{{ ds1 }}'
    datastore_type: '{{ infra.datastores[ds1].type }}'
    nfs_server: '{{ infra.datastores[ds1].server }}'
    nfs_path: '{{ infra.datastores[ds1].path }}'
    nfs_ro: '{{ infra.datastores[ds1].ro }}'
    state: present
    validate_certs: no
  with_items: "{{ esxi_hosts }}"

- name: Mount NFS (ds2) datastores on the ESXi
  vmware_host_datastore:
    hostname: '{{ item }}'
    username: '{{ esxi_user }}'
    password: '{{ esxi_password }}'
    datastore_name: '{{ ds2 }}'
    datastore_type: '{{ infra.datastores[ds2].type }}'
    nfs_server: '{{ infra.datastores[ds2].server }}'
    nfs_path: '{{ infra.datastores[ds2].path }}'
    nfs_ro: '{{ infra.datastores[ds2].ro }}'
    state: present
    validate_certs: no
  with_items: "{{ esxi_hosts }}"

- name: The vcenter needs a bit of time to refresh the DS list
  vmware_datastore_info:
    validate_certs: false
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    cluster: '{{ ccr1 }}'
  register: setup_datastore_datatstore_info
  failed_when: setup_datastore_datatstore_info.datastores|selectattr('type', 'equalto', 'NFS')|list|length != 2
  until: setup_datastore_datatstore_info is succeeded
  retries: 60
  delay: 1
