ansible / ansible

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy and maintain. Automate everything from code deployment to network configuration to cloud management, in a language that approaches plain English, using SSH, with no agents to install on remote systems. https://docs.ansible.com.
https://www.ansible.com/
GNU General Public License v3.0
63.12k stars 23.93k forks source link

win_disk_image fails when image is already mounted #54723

Closed neilalexander closed 4 years ago

neilalexander commented 5 years ago
SUMMARY

The win_disk_image target seems to fail occasionally when the disk image is already mounted, breaking idempotency.

ISSUE TYPE
COMPONENT NAME

win_disk_image

ANSIBLE VERSION
ansible 2.7.9
  config file = None
  configured module search path = [u'/Users/neilalexander/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible
  executable location = /Library/Frameworks/Python.framework/Versions/2.7/bin/ansible
  python version = 2.7.15 (v2.7.15:ca079a3ea3, Apr 29 2018, 20:59:26) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]
CONFIGURATION
none
OS / ENVIRONMENT

Ansible is running on macOS Mojave 10.14.3. Target server is Windows Server 2016.

STEPS TO REPRODUCE

Happens only intermittently. Can't seem to reproduce 100% of the time.

win_disk_image:
  image_path: 'C:\path\to\isoimage.iso'
  state: present
EXPECTED RESULTS
ACTUAL RESULTS

MODULE_STDERR: The property 'DriveLetter' cannot be found on this object. Verify that the property exists. At line:52 char:7+ $drive_letters = ($di | Get-Volume).DriveLetter

ansibot commented 5 years ago

Files identified in the description:

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

ansibot commented 5 years ago

cc @dagwieers @if-meaton @jborean93 @jhawkesworth @nitzmahone click here for bot help

jborean93 commented 5 years ago

Hmm I can't seem to replicate this issue but it looks like it comes down to $di | Get-Volume returning $null which means it cannot access the DriveLetter property. The $di value itself can't be $null or else it would fail with

Get-Volume : Cannot validate argument on parameter 'StorageJob'. The argument is null. Provide a valid value for the
argument, and then try running the command again.
At line:1 char:8
+ ($di | Get-Volume).DriveLetter
+        ~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Get-Volume], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Get-Volume

I tried stress testing my host so maybe WMI would return nothing under load but still no luck. Technically we could check if the result is $null before accessing the DriveLetter but we should still fail because we couldn't return the mounted drive letter(s).

neilalexander commented 5 years ago

The issue only seems to happen sporadically, and I've only noticed it on one machine (which gets wiped back to a blank snapshot often enough) although I haven't really tried this method on other machines yet – haven't got that far!

I'm wondering whether the issue might be related to if the ISO file gets overwritten/redownloaded before mounting? I am not really sure how Windows detects if a file is already mounted or not.

The ISO is the SCCM 1802 install media (mu_system_center_configuration_manager_current_branch_version_1802_x86_x64_dvd_12064903.iso from MSDN).

neilalexander commented 5 years ago

Hm, never mind. I don't believe the local copy of the ISO is being rewritten before the second re-mount after all. The win_get_url task has force: no and it does not report changed status.

Here's what I see on the machine:

PS C:\Users\Administrator> Get-DiskImage C:\Users\Administrator\AppData\Local\Temp\mu_system_center_configuration_manager_current_branch_version_1802_x86_x64_dvd_12064903.iso | Get-Volume

DriveLetter FileSystemLabel FileSystem DriveType HealthStatus OperationalStatus SizeRemaining   Size
----------- --------------- ---------- --------- ------------ ----------------- -------------   ----
E           SC_CM_SCEP_1802 UDF        CD-ROM    Healthy      OK                          0 B 1.4 GB
ansibot commented 5 years ago

Files identified in the description:

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

ansibot commented 5 years ago

cc @ShachafGoldstein click here for bot help

jborean93 commented 4 years ago

Issue migrated to https://github.com/ansible-collections/community.windows/issues/36