ansible-collections / community.vmware

Ansible Collection for VMware
GNU General Public License v3.0
346 stars 334 forks source link

vmware_host_scanhba missing option to scan VMFS Volumes #479

Closed julie-blake-verizon closed 2 years ago

julie-blake-verizon commented 3 years ago
SUMMARY

The module vmware_host_scanhba seems to be missing the option to "Scan for new VMFS Volumes". When a host is added to an existing cluster, all the storage already has VMFS volumes, but using vmware_host_scanhba , even with refresh_storage: True does not see the datastores.

From the vCenter GUI: Rescan Storage [check mark] Scan for new Storage Devices Rescan all host bus adapters for new storage devices. Rescanning all adapters can be slow. Scan for new VMFS Volumes [check mark] Rescan all known storage devices for new VMFS volumes that have been added since the last scan. Rescanning known storage for new file systems is faster than rescanning for new storage.

ISSUE TYPE
COMPONENT NAME

vmware_host_scanhba

ANSIBLE VERSION
ansible 2.9.12
  config file = /opt/ansible/etc/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.6.8 (default, Aug  7 2019, 17:28:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
CONFIGURATION
DEFAULT_HOST_LIST(/opt/ansible/etc/ansible.cfg) = ['/opt/ansible/inventory']
DEFAULT_ROLES_PATH(/opt/ansible/etc/ansible.cfg) = ['/opt/ansible/roles']
DEFAULT_VAULT_PASSWORD_FILE(/opt/ansible/etc/ansible.cfg) = <REDACTED>
OS / ENVIRONMENT

vCenter 6.7.0.42000, VMware ESXi, 6.7.0, 14320388

STEPS TO REPRODUCE
- name: "hba scan for {{ host_stanza.hostname }}"
  vmware_host_scanhba:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    validate_certs: "{{ vcenter_validate_certs }}"
    esxi_hostname: "{{ host_stanza.hostname }}"
    refresh_storage: True
  register: hbascan_out
  when: scan_storage
EXPECTED RESULTS
changed: [testserver] => {
    "changed": true,
    "invocation": {
        "module_args": {
            "cluster_name": null,
            "esxi_hostname": "<REDACTED>",
            "hostname": "<REDACTED>",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 443,
            "proxy_host": null,
            "proxy_port": null,
            "refresh_storage": true,
            "username": "ansible@vsphere.local",
            "validate_certs": false
        }
    },
    "result": {
        "<REDACTED>": {
            "refreshed_storage": true,
            "rescaned_hba": true
        }
    }
}
Runs the vSphere tasks:
Rescan all HBAs & Rescan VMFS
ACTUAL RESULTS

Doesn't find the storage volumes and then the next step, which ensures that the datastores DO exist, fails.

failed: [testserver] (item=Datastore prodwin_sas_ds01 is present) => {
    "ansible_loop_var": "datastore",
    "changed": false,
    "datastore": {
        "datastore_name": "prodwin_sas_ds01",
        "vmfs_device_name": "naa.600a098038314341793f505966466a7a",
        "vmfs_version": 6
    },
    "invocation": {
        "module_args": {
            "datacenter_name": null,
            "datastore_name": "prodwin_sas_ds01",
            "datastore_type": "vmfs",
            "esxi_hostname": "<REDACTED>",
            "hostname": "<REDACTED>",
            "nfs_path": null,
            "nfs_ro": false,
            "nfs_server": null,
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 443,
            "proxy_host": null,
            "proxy_port": null,
            "state": "present",
            "username": "ansible@vsphere.local",
            "validate_certs": false,
            "vmfs_device_name": "naa.600a098038314341793f505966466a7a",
            "vmfs_version": 6
        }
    },
    "msg": "Cannot mount datastore prodwin_sas_ds01 on host <REDACTED> : list index out of range"
}
Akasurde commented 3 years ago

@julie-blake-verizon Thanks for reporting this issue. Could you please do the following command on the esxi_hostname

# ls /vmfs/devices/disks/
mariolenz commented 3 years ago

This is the core functionality of the module:

https://github.com/ansible-collections/community.vmware/blob/54403d612d2b604b11e7dd5464b7585a26dc1dae/plugins/modules/vmware_host_scanhba.py#L112

The documentation isn't clear to me:

Scans all host bus adapters to obtain the current list of devices and device topology. The RescanAllHba method looks for new devices, removed devices, and path changes.

This method may update the following inventory elements:

  • Devices and storage topology (HostSystem.Config.storageDevice).
  • VMFS and NFS datastores (HostSystem.Datastore).
  • File system volumes (HostSystem.Config.fileSystemVolume).

Scanning for devices and device topology doesn't sound like it scans for filesystems, but since it "may update VMFS and NFS datastores" sounds like it does.

Anyway:

The Server performs asynchronous updates to the inventory. Use the PropertyCollector.WaitForUpdatesEx method to obtain the property changes.

Since the scan or at least the inventory update is asynchronous, we might have to somehow wait for it to finish so later tasks can work with the new devices / datastores. Otherwise, they might run before the asynchronous scan finished.

julie-blake-verizon commented 3 years ago

It isn't working no matter how long I wait. I commented out the second part and just waited, and it didn't come up after 10 minutes. If I look in the vCenter Recent Tasks display during the ansible code run, it shows a task running "Rescan all HBAs", but no "Rescan VMFS" task ever starts.

Akasurde commented 3 years ago

@julie-blake-verizon Thanks for reporting this issue. Could you please do the following command on the esxi_hostname

# ls /vmfs/devices/disks/

@julie-blake-verizon ^^^

Akasurde commented 3 years ago

Now, there is a module to gather information about the SCSI disk attached to the given ESXi - https://github.com/ansible-collections/community.vmware/blob/main/plugins/modules/vmware_host_iscsi_info.py.

ansibullbot commented 3 years ago

@julie-blake-verizon This issue is waiting for your response. Please respond or the issue will be closed.

click here for bot help

ansibullbot commented 3 years ago

cc @Tomorrow9 @goneri @lparkes @michaeldeaton @pgbidkar @warthog9 click here for bot help

ghernandeza commented 3 years ago

Its missing the line:

host.configManager.storageSystem.RescanVmfs()

after:

host.configManager.storageSystem.RescanAllHba()

ansibullbot commented 3 years ago

@julie-blake-verizon You have not responded to information requests in this issue so we will assume it no longer affects you. If you are still interested in this, please create a new issue with the requested information.

click here for bot help

ebkde commented 2 years ago

Please consider reopening this issue. I can confirm the behavior @julie-blake-verizon is describing and can verify it in my own environment. Additionally I can confirm, that the patch @ghernandeza proposed in https://github.com/ansible-collections/community.vmware/issues/479#issuecomment-829119631 is working.

ebkde commented 2 years ago

thank you for reopening. I created a pull request to adress this --> https://github.com/ansible-collections/community.vmware/pull/1137

mariolenz commented 2 years ago

I think this issue has been resolved by #1137. Please re-open it or open a new one if you think otherwise.