Windows – How can I use Ansible to perform actions on any file in a particular location?

I'm building game books to provide a Windows application that requires some prerequisites (Visual C ++ runtime and DotNet framework) before installing the application itself.
These prerequisites are .EXE files and are all located in a specific folder.

I want to create an Ansible playbook that executes (among other things) any of the .EXE files in the Preriquisites folder with the parameters "/ install / passive".

I do not want to have to specify every filename in my playbook.

My idea was to first find the prerequisite setup files with the "win_file" module, assign the result to a variable and iterate over the variable and execute the "win_command" module for each file it contains.

Unfortunately, I can not assign the win_find result to a variable using the register statement; nothing is executed.

I have tried the following:

- hosts: "{{target}}"


- name: find files in the path
register: myvar
Paths: E:  Temp  Prognosis_11.2  Prerequisites

- name: debug
msg: "{{myvar}}"

And the output of the playbook when run with -v (verbose mode):

TASK [Find files in path] ************************************************** **************************************************************************************** **** ****************************************************************************************** ****** ****

OK: [SMN001] => {"changed": wrong, "checked": 5, "files": [{“attributes”: “Archive”, “checksum”: “3049a85843eaf65e89e2336d5fe6e85e416797be”, “creationtime”: 1550942958.6690862, “extension”: “.exe”, “filename”: “NDP46-KB3045557-x86-x64-AllOS-ENU.exe”, “isarchive”: true, “isdir”: false, “ishidden”: false, “islnk”: false, “isreadonly”: false, “isshared”: false, “lastaccesstime”: 1550942958.6690862, “lastwritetime”: 1459427148, “owner”: “BUILTINAdministrators”, “path”: “E:TempPrognosis_11.2PrerequisitesNDP46-KB3045557-x86-x64-AllOS-ENU.exe”, “size”: 65444688}, {“attributes”: “Archive”, “checksum”: “8bf41ba9eef02d30635a10433817dbb6886da5a2”, “creationtime”: 1550942958.7627323, “extension”: “.exe”, “filename”: “vcredist2013_x64.exe”, “isarchive”: true, “isdir”: false, “ishidden”: false, “islnk”: false, “isreadonly”: false, “isshared”: false, “lastaccesstime”: 1550942958.7627323, “lastwritetime”: 1489501866, “owner”: “BUILTINAdministrators”, “path”: “E:TempPrognosis_11.2Prerequisitesvcredist2013_x64.exe”, “size”: 7194312}, {“attributes”: “Archive”, “checksum”: “df7f0a73bfa077e483e51bfb97f5e2eceedfb6a3”, “creationtime”: 1550942958.7779777, “extension”: “.exe”, “filename”: “vcredist2013_x86.exe”, “isarchive”: true, “isdir”: false, “ishidden”: false, “islnk”: false, “isreadonly”: false, “isshared”: false, “lastaccesstime”: 1550942958.7779777, “lastwritetime”: 1489501866, “owner”: “BUILTINAdministrators”, “path”: “E:TempPrognosis_11.2Prerequisitesvcredist2013_x86.exe”, “size”: 6503984}, {“attributes”: “Archive”, “checksum”: “007064d974a55940838f19cd0b0e3aaf27ca06a7”, “creationtime”: 1550942958.7939014, “extension”: “.exe”, “filename”: “vcredist2017_x64.exe”, “isarchive”: true, “isdir”: false, “ishidden”: false, “islnk”: false, “isreadonly”: false, “isshared”: false, “lastaccesstime”: 1550942958.7939014, “lastwritetime”: 1488965662, “owner”: “BUILTINAdministrators”, “path”: “E:TempPrognosis_11.2Prerequisitesvcredist2017_x64.exe”, “size”: 15261400}, {“attributes”: “Archive”, “checksum”: “ba1f7e7cace62f7c55ab948cd3b29acc4e8e2329”, “creationtime”: 1550942958.8406758, “extension”: “.exe”, “filename”: “vcredist2017_x86.exe”, “isarchive”: true, “isdir”: false, “ishidden”: false, “islnk”: false, “isreadonly”: false, “isshared”: false, “lastaccesstime”: 1550942958.8406758, “lastwritetime”: 1488965662, “owner”: “BUILTINAdministrators”, “path”: “E:TempPrognosis_11.2Prerequisitesvcredist2017_x86.exe”, “size”: 14401656}], "tuned": 5}

TASK [debug] ************************************************** **************************************************************************************** **** ****************************************************************************************** ****** *****************

fatal: [SMN001]: FAILED! => {"msg": "The task contains an option with an undefined variable The error was: & # 39; myvar & # 39; is undefined n nThe error appears in & # 39; / etc / ansible / playbooks / test_find_files.yaml: line 18, column 5, but may be elsewhere in the file, depending on the exact syntax problem. n nThe faulty line appears to be: n n n – Name: debug n ^ here n "}

As you can see, the files are found correctly, but the variable "myvar" does not exist, even though it should be assigned.

According to this page, this logic seems to work on Linux hosts: (see "Saving File Names in a Register") footer).

Could it be a problem with the win_find module itself?
Any thoughts?

Many Thanks!