diff --git a/plugins/modules/win_mapped_drive.ps1 b/plugins/modules/win_mapped_drive.ps1 index 93d95feb..030d36c8 100644 --- a/plugins/modules/win_mapped_drive.ps1 +++ b/plugins/modules/win_mapped_drive.ps1 @@ -390,11 +390,6 @@ try { } } else { - $physical_drives = Get-PSDrive -PSProvider "FileSystem" - if ($letter -in $physical_drives.Name) { - $module.FailJson("failed to create mapped drive $letter, this letter is in use and is pointing to a non UNC path") - } - # PowerShell converts a $null value to "" when crossing the .NET marshaler, we need to convert the input # to a missing value so it uses the defaults. We also need to Invoke it with MethodInfo.Invoke so the defaults # are still used @@ -418,6 +413,11 @@ try { } } else { + $physical_drives = Get-PSDrive -PSProvider "FileSystem" + if ($letter -in $physical_drives.Name) { + $module.FailJson("failed to create mapped drive $letter, this letter is in use and is pointing to a non UNC path") + } + if (-not $module.CheckMode) { $add_method.Invoke($null, [Object[]]@($letter_root, $path, $i_token_ptr, $input_username, $input_password)) } diff --git a/tests/integration/targets/win_mapped_drive/tasks/main.yml b/tests/integration/targets/win_mapped_drive/tasks/main.yml index 19d5acb2..c03c341e 100644 --- a/tests/integration/targets/win_mapped_drive/tasks/main.yml +++ b/tests/integration/targets/win_mapped_drive/tasks/main.yml @@ -60,7 +60,7 @@ ansible_become: yes ansible_become_method: runas ansible_become_user: '{{ ansible_user }}' - ansible_become_pass: '{{ ansible_password }}' + ansible_become_pass: '{{ ansible_password | default(ansible_test_connection_password) }}' - name: ensure mapped drive is deleted at the end of the test win_mapped_drive: diff --git a/tests/integration/targets/win_mapped_drive/tasks/tests.yml b/tests/integration/targets/win_mapped_drive/tasks/tests.yml index 2529b8ba..a7d47ca2 100644 --- a/tests/integration/targets/win_mapped_drive/tasks/tests.yml +++ b/tests/integration/targets/win_mapped_drive/tasks/tests.yml @@ -283,7 +283,7 @@ ansible_become: yes ansible_become_method: runas ansible_become_user: '{{ ansible_user }}' - ansible_become_pass: '{{ ansible_password }}' + ansible_become_pass: '{{ ansible_password | default(ansible_test_connection_password) }}' - name: map drive with stored cred (check mode) win_mapped_drive: