Im afraid that didnt work. Still getting the same issues.
I've been playing with win_shell also and still same issue. Im actually
executing two roles in my playbook. The first role is Add storage creds &
map drive & the second is the copy file.
- name: Add storage creds & map drive
block:
- name: Adding creds for mapped drive
win_credential:
name: storage.file.core.windows.net
type: domain_password
username: localhost\storage
secret: "{{ storage_account_keys.json['keys'].0.value }}"
- name: Map drive
win_mapped_drive:
letter: Z
path: \\storage.file.core.windows.net\cmdb
username: localhost\storage
password: "{{ storage_account_keys.json['keys'].0.value }}"
vars:
ansible_become: yes
ansible_become_method: runas
ansible_become_user: "{{ ansible_user }}"
ansible_become_password: "{{ ansible_password }}"
- name: Copy File
#win_shell: Copy-Item
Z:\Software\Microsoft\dotNET3\microsoft-windows-netfx3.cab -Destination "{{
Generic_Temp_Path }}\\dotNET53\\microsoft-windows-netfx3.cab"
win_shell: Copy-Item
\\storage.file.core.windows.net\cmdb\Software\Microsoft\dotNET3\microsoft-windows-netfx3.cab
-Destination "{{ Generic_Temp_Path
}}\\dotNET53\\microsoft-windows-netfx3.cab"
vars:
become: true
become_method: runas
#become_user: SYSTEM
become_user: "{{ ansible_user }}"
become_password: "{{ ansible_password }}"
#become_flags: logon_type=new_credentials
logon_flags=netcredentials_only
become_flags: logon_type=interactive logon_flags=netcredentials_only
If I login as {{ ansible_user }} and run net use without UAC and I can see
the Z:. Yet Ansible will not copy the file. Ive played with various
become flags and all fail.
Any ideas?
Cheers!
On Saturday, 19 August 2023 at 18:18:02 UTC+1 Atul Nasir wrote:
> ---
> - name: Copy dotNET 3.5 CAB File to Server and Troubleshoot
> hosts: your_target_host
> tasks:
> - name: Check if Mapped Drive Exists
> win_shell: dir Z:
> register: mapped_drive_status
> ignore_errors: yes # Ignore errors, we just want to check if drive
> is accessible
>
> - name: Debug Mapped Drive Status
> debug:
> var: mapped_drive_status
>
> - name: Use UNC Path if Mapped Drive is Unavailable
> set_fact:
> use_unc_path: "{{ 'false' if mapped_drive_status.failed else
> 'true' }}"
>
> - name: Copy dotNET 3.5 CAB File to Server using UNC Path
> win_copy:
> src: "\\{{ storage_account_name }}.file.core.windows.net
> \share\Software\Microsoft\dotNET3\microsoft-windows-netfx3.cab"
> dest: "{{ Generic_Temp_Path }}\\dotNET53"
> when: use_unc_path == 'true'
>
> - name: Check File Existence on Mapped Drive
> win_stat:
> path:
> "Z:\\Software\\Microsoft\\dotNET3\\microsoft-windows-netfx3.cab"
> register: file_status
>
> - name: Display File Status on Mapped Drive
> debug:
> var: file_status
>
> - name: Copy dotNET 3.5 CAB File to Server using Mapped Drive
> win_copy:
> src:
> "Z:\\Software\\Microsoft\\dotNET3\\microsoft-windows-netfx3.cab"
> dest: "{{ Generic_Temp_Path }}\\dotNET53"
> when: file_status.stat.exists
>
> - name: Display Debug Information
> debug:
> msg: "UNC Path: {{ use_unc_path }} | File Exists: {{
> file_status.stat.exists }}"
>
> On Wednesday, August 16, 2023 at 10:53:37 AM UTC-7 Brad wrote:
>
>> Hi,
>>
>> I'm trying to get Ansible to copy files from a mapped azure drive locally
>> but I keep getting the below error:
>>
>> fatal: [192.168.1.193]: FAILED! => {"changed": false, "dest":
>> "C:\\Temp\\dotNET53", "msg": "Cannot copy src file:
>> 'Z:\\Software\\Microsoft\\dotNET3\\microsoft-windows-netfx3.cab' as it does
>> not exist", "src":
>> "Z:\\Software\\Microsoft\\dotNET3\\microsoft-windows-netfx3.cab"}
>>
>> My code is:
>>
>> - name: Copy dotNET 3.5 CAB File to Server
>> win_copy:
>> src: Z:\Software\Microsoft\dotNET3\microsoft-windows-netfx3.cab
>> dest: "{{ Generic_Temp_Path }}\\dotNET53"
>> remote_src: true
>>
>> All the online reading I've done seems to point to double hop creds being
>> the issue. But I'm a bit stuck since the authentication to the mapped
>> drive is using the storage key as the pass and localhost\storageaccountname
>> as username.
>>
>> If I log in as ansible_user then run net use shows the drive mapped. I
>> can't switch to Azure AD auth as the boxes may or may not be joined.
>>
>> Has anyone got any suggestions? I didnt think this would be so complex
>> haha!
>>
>> Thanks,
>>
>> Brad.
>>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/292c1cf2-1494-4495-b16d-820872f36d31n%40googlegroups.com.