A few things - Each task is run in a completely separate shell from each other, running net use in a previous task won't have any affect on any subsequent tasks - Don't try to use mapped drives with Ansible, or really any other non-interactive purpose - Mapped drives are really only useful for interactive logons, they don't play well for anything else If you are trying to access an msi from a network path the method we recommend is to use become like so
- name: Install MSI win_package: path: \\xxxx\tttt\ppp\Application.msi state: present become: yes become_method: runas become_flags: logon_type=new_credentials logon_flags=netcredentials_only vars: ansible_become_user: domain\user ansible_become_pass: pass We cover more about become and WIndows at https://docs.ansible.com/ansible/latest/user_guide/become.html#become-and-windows but what that task basically does is to run your installer using the connection user but any outbound network attempts will use those credentials, just like net use would do. On Saturday, October 31, 2020 at 7:28:37 AM UTC+10 smart aquarius wrote: > Team, > > My ansible version is 2.9.1. Here I'm trying to install a msi, placed in a > shared drive, on windows 10 VDI. > > These are 2 play books I've tried > > ----------------------------------------------------------------------- > *- name: Install Monitoring Service for VDI* > * hosts: all* > > * tasks:* > * - name: Maping Network Drive* > * win_command: net use "Z:" "\\xxxx\tttt\ppp" /user:domain\user > "pass"* > > * - name: Directory* > * win_command: net use* > > * - name: Install MSI* > * win_package:* > * path: \\xxxx\tttt\ppp\Application.msi* > * state: present* > > * - name: Unmap drive* > * win_command: net use "Z:" /delete* > > In this case I get this error at msi installation stage > > The full traceback is: > Access is denied > At line:196 char:27 > + ... $valid_path = Test-Path -LiteralPath $test_path -PathType Leaf > + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > + CategoryInfo : PermissionDenied: > (\\xxxx\tt...pp\Application.msi:String) [Test-Path], > UnauthorizedAccessException > + FullyQualifiedErrorId : > ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.TestPathCommand > > ScriptStackTrace: > at Get-ProgramMetadata, <No file>: line 196 > at <ScriptBlock>, <No file>: line 301 > > System.UnauthorizedAccessException: Access is denied ---> > System.ComponentModel.Win32Exception: Access is denied > --- End of inner exception stack trace --- > at Microsoft.PowerShell.Commands.FileSystemProvider.ItemExists(String > path, ErrorRecord& error) > fatal: [IP address]: FAILED! => { > "changed": false, > "msg": "Unhandled exception while executing module: Access is denied" > > ----------------------------------------------------------------------- > --------------------------------------------------------------------- > > In 2nd Playbook I have changed the msi path to local drive like this > > - name: Install MSI > win_package: > path: *Z:\\Application.msi* > state: present > > And the error I get > > fatal: [IP address]: FAILED! => { > "changed": false, > "msg": "the file at the local path Z:\\\\Application.msi cannot be > reached", > "reboot_required": false > } > ----------------------------------------------------------------------- > ----------------------------------------------------------------------- > In both the cases, after running the playbook, the output of the 2nd > command > * name: Directory* > * win_command: net use* > > "New connections will be remembered.", > "", > "", > "Status Local Remote Network", > "", > > "-------------------------------------------------------------------------------", > "Unavailable Z: \\xxxx\tttt\ppp ", > " Microsoft Windows > Network", > "The command completed successfully.", > ----------------------------------------------------------------------- > ----------------------------- > > The authentication I'm using is ntlm and in my organization only ntlm and > kerberos is allowed. > > Any suggestions here. Can anyone suggest a way to install this msi. I've > tried to install msi using manual steps in which: > > 1. Created Enter-PsSession with windows 10 workstation remotely > 2. mapped the shared drive using net use command > 3. Installed using msiexec command > > This is working. Then why it is not working with ansible because > Enter-PsSession also use winrm. Please help!! > > Thank you > > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e5d35909-25cb-4b2e-aa42-2c00fa3ea4a9n%40googlegroups.com.