Using credentials in a PowerShell script over WinRM is not always possible if you cannot use Kerberos delegation. For this cases you can use “Credential Security Provider (CredSSP)” authentication. With this protocol its is possible to share credentials with a target machine. This is what they call “Multi-hop” support. Enabeling this protocol lets you access fileshares on other computers.
Using win_copy from a Windows File share with Ansible
So for everyone who is struggling how to access file-shares on a Windows server with ansible. Iam using WinRM CredSSP. The following code is working on my environment:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
- name: CopyFiles hosts: win tasks: - name: Copy a single file as another user win_copy: src: "{{ CIFSSharePath }}{{ OST.exe}}" dest: "c:\\TESTPath\\TESTPath\\{{ OST.exe }}" remote_src: yes become: yes become_method: runas become_flags: logon_type=new_credentials logon_flags=netcredentials_only vars: ansible_become_user: "{{ cifsuser }}" ansible_become_password: "{{ cifspw }}" ansible_remote_tmp: 'c:\install\tmp' |