i am getting below error when run the playbook:
fatal: [localhost]: UNREACHABLE! => {“changed”: false, “msg”: “ssl: auth method ssl requires a username”, “unreachable”: true}
The error you have is nothing to do with mapped drives but that Ansible is unable to authenticate itself over the WinRM connection. YOu need to set ansible_user and ansible_password for Ansible to use as the connection credentials.
Also please note that while you can map a network drive using win_mapped_drive in Ansible, you cannot use that mapped drive in Ansible tasks. That mapping is just for interactive logons. If you want to access files from a network path in Ansible you need to use the UNC path and potentially use become to add outbound creds to your process. We have an example of that here https://docs.ansible.com/ansible/latest/user_guide/become.html#become-flags-for-windows.
So the drive mapping is present but Windows is unable to map the drive on logon. You can use the win_credential [1] to store a credential that Windows will use for mapped drives. There’s even an example of this in the win_mapped_drive [2] docs. If you are running the net use command through Ansible and expecting to see that mapped drive available then you are out of luck. Mapped drives are only for use with interactive logons and not for use in Ansible, Ansible can only manage the mappings but not use them.
I tried the below playbook to store the credential that Windows will use for mapped drives. But it is throwing the below error :
hosts: [win]
gather_facts: false
tasks:
name: Save the network credentials required for the mapped drive
win_credential:
name: 10.224.233.199 -----> windows machine IP
type: domain_password
state: present #persistence: local #secret_format: text #update_secret: always
username: Administrator-----> windows machine username
secret: opteamix------> windows machine password
become: yes
become_method: runas
vars:
become is required to save and retrieve the credentials in the tasks
ansible_become_user: apple ----- username of the drive to be mapped.
ansible_become_pass: barharbour -----password of the drive to be mapped.
ansible_become_flags: logon_type=new_credentials logon_flags=netcredentials_only
fatal: [10.234.224.199]: FAILED! => {
“changed”: false,
“msg”: “Unhandled exception while executing module: Exception calling "GetCredential" with "2" argument(s): "Failed to access the user’s credential store, run the module with become"”