I have a playbook that search in Windows host for a file pattern. This file can be found for more users. When found the file is copied to a different folder but concatenated with the username where the file was found and with the host.My problem is to copy the "new files" in my computer where I have problems. I think because of the how the files are named. THis is my code, which work well till last task:
- name: Get hostname of the target Windows host ansible.builtin.win_shell: hostname register: hostname_result - name: Clean hostname by stripping newline characters ansible.builtin.set_fact: clean_hostname: "{{ hostname_result.stdout | trim }}" - name: Search for *emphasized text*CQI.log file ansible.builtin.win_shell: | $files = Get-ChildItem -Path "C:\Users\*\AppData\CQI" -Filter "CQI.log" -Recurse -ErrorAction SilentlyContinue -Force if ($files) { $files.FullName -join "`n" } register: found_files changed_when: false - name: Create directory ansible_tmp in C:\ ansible.windows.win_file: path: C:\ansible_tmp state: directory when: found_files.stdout != "" and hostname_result.stdout != "" - name: Copy file to target path with hostname and username in the name ansible.windows.win_copy: src: "{{ item }}" dest: "C:\\ansible_tmp\\CQI_{{ clean_hostname }}_{{ item | regex_search('Users\\\\([^\\\\]+)\\\\AppData', '\\1') }}.log" remote_src: true with_items: "{{ found_files.stdout_lines }}" when: found_files.stdout != "" and hostname_result.stdout != "" failed_when: false - name: Find all files in Windows folder win_find: paths: "C:\\ansible_tmp\\" patterns: "*" # Find all files with wildcard register: files_to_copy - name: Copy each file to Linux VM ansible.builtin.fetch: src: "{{ item.path }}" dest: "/mnt/d/test/{{ item.filename }}" loop: "{{ files_to_copy.files }}"
The file has this format : CQI__['user_test'].log
I am running Ansible on WIndows + WSL and all the hosts are Windows.And I have problems with coping this files back to my computer from ansible_tmp. Do you have any ideea how this can be done ?