ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
200 stars 154 forks source link

Problems with win_mapped_drive not using credentials #96

Open rnc opened 4 years ago

rnc commented 4 years ago
SUMMARY

I have been working with @jborean93 offline and he suggested I enter a ticket.

The problem I am having is getting win_mapped_drive to see the credentials I entered using win_credential and use them to map the drive.

ISSUE TYPE
COMPONENT NAME

win_mapped_drive

ANSIBLE VERSION
ansible 2.9.9
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/rnc/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.7.7 (default, Mar 13 2020, 10:23:39) [GCC 9.2.1 20190827 (Red Hat 9.2.1-1)]
CONFIGURATION
DEFAULT_HOST_LIST(/home/rnc/Work/Miscellaneous/nicks-shell/ansible-windows/ansible.cfg) = ['/home/rnc/Work/Miscellaneous/nicks-shell/ansible-windows/hosts']
DEFAULT_VAULT_PASSWORD_FILE(/home/rnc/Work/Miscellaneous/nicks-shell/ansible-windows/ansible.cfg) = /home/rnc/Work/Miscellaneous/nicks-shell/ansible-windows/vault.sh
OS / ENVIRONMENT

Running Ansible ansible-2.9.9-1.fc31.noarch on Fedora release 31 (Thirty One) Windows is running on VirtualBox (6.1.8_RPMFusion r137981) Windows version

STEPS TO REPRODUCE

  - name: Mapping Drives
    block:
    - name: Save credentials
      win_credential:
        name: 192.168.0.168
        type: domain_password
        username: cross  # Also tried '192.168.0.168\cross'
        secret: '{{ synology_family_pass }}'
        state: present

    - name: Music
      win_mapped_drive:
        letter: M
        path: \\192.168.0.168\music
        state: present
    become: yes
    become_method: runas
    vars:
      ansible_become: yes
      ansible_become_method: runas
      ansible_become_user: '{{ ansible_user }}'
      ansible_become_password: '{{ ansible_password }}' 

does not work, but the below does work:

  - name: Mapping Drives
    block:
    - name: Save credentials
      win_credential:
        name: 192.168.0.168
        type: domain_password
        username: cross
        secret: '{{ synology_family_pass }}'
        state: present

    - name: run net use to setup mapped drives
      win_shell: |
        if (!(Test-Path M:)) { NET USE M: \\192.168.0.168\music /PERSISTENT:YES }
        if (!(Test-Path P:)) { NET USE P: \\192.168.0.168\photo /PERSISTENT:YES }
        if (!(Test-Path V:)) { NET USE V: \\192.168.0.168\video /PERSISTENT:YES }

    become: yes
    become_method: runas
    vars:
      ansible_become: yes
      ansible_become_method: runas
      ansible_become_user: '{{ ansible_user }}'
      ansible_become_password: '{{ ansible_password }}'
EXPECTED RESULTS
ACTUAL RESULTS

I have examined the password in the credential provider using CredentialsFileView from nirsoft.net and it is correct. The variable 'synology_family_pass' is from an ansible vault. I have tested a manual local mapping as per the cmdkey & netuse and it works fine. I eventually switched to using net use and it works fine.


TASK [Save credentials] *************************************************************************************************************************************************************************
task path: /home/rnc/Work/Miscellaneous/nicks-shell/ansible-windows/playbook.yml:113
changed: [192.168.42.1] => {"changed": true}

TASK [Music] ************************************************************************************************************************************************************************************
task path: /home/rnc/Work/Miscellaneous/nicks-shell/ansible-windows/playbook.yml:121
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: at <ScriptBlock>, <No file>: line 420
fatal: [192.168.42.1]: FAILED! => {"changed": false, "msg": "Unhandled exception while executing module: Exception calling \"Invoke\" with \"2\" argument(s): \"Failed to map M: to '\\\\192.168.0.168\\music' with WNetAddConnection2W() (The specified network password is not correct, Win32ErrorCode 86)\""}
MSZ-Spyro commented 1 week ago

Ive got exactly the same issue now, but only on win11 0_o works fine on win10 0_o Did you find any solution or cause ?