After connecting to share folder \10.14.2.130\shared\ , I am trying to search for files in 'Data' folder inside the share folder.
- name: Search for files in Data folder
win_find:
paths: \\10.14.2.130\shared\folder\Data\
register: file1
The task is supposed to show that there is a file in the folder. However, this was the error I got:
**[WARNING]: Argument path '\\10.14.2.130\shared\folder\Data\' does not exist or is not accessible, skipping**
ok: [10.12.201.60] => {
"changed": false,
"examined": 0,
"files": [],
"invocation": {
"module_args": {
"age": null,
"age_stamp": "mtime",
"checksum_algorithm": "sha1",
"file_type": "file",
"follow": false,
"get_checksum": true,
"hidden": false,
"paths": [
"\\\\10.14.2.130\\shared\\folder\\Data\\"
],
"patterns": null,
"recurse": false,
"size": null,
"use_regex": false
}
},
"matched": 0
}
However, when I run the same task on the share folder host itself (10.14.2.130), it manages to output the result that there is a file in the folder:
ok: [10.14.2.130] => {
"changed": false,
"examined": 1,
"files": [
{
"attributes": "Archive",
"checksum": "141a1f8872be45d532973c56688cf800700b01bb",
"creationtime": 1678294890.4031632,
"exists": true,
"extension": ".csv",
"filename": "sample.csv",
"hlnk_targets": [],
"isarchive": true,
"isdir": false,
"ishidden": false,
"isjunction": false,
"islnk": false,
"isreadonly": false,
"isreg": true,
"isshared": false,
"lastaccesstime": 1678294890.4031632,
"lastwritetime": 1677091528,
"lnk_source": null,
"lnk_target": null,
"nlink": 1,
"owner": "BUILTIN\\Administrators",
"path": "\\\\10.14.2.130\\shared\\folder\\Data\\sample.csv",
"sharename": null,
"size": 949
}
],
"invocation": {
"module_args": {
"age": null,
"age_stamp": "mtime",
"checksum_algorithm": "sha1",
"file_type": "file",
"follow": false,
"get_checksum": true,
"hidden": false,
"paths": [
"\\\\10.14.2.130\\shared\\folder\\Data\\"
],
"patterns": null,
"recurse": false,
"size": null,
"use_regex": false
}
},
"matched": 1
Edit: I used this task to connect to share folder:
- name: Connect to shared folder
win_command: 'net use Z: \\10.14.2.130\shared\ /user:username passwordhere /p:yes'
become: yes
become_method: runas
become_user: SYSTEM
I have checked and found out that it shows up as a disconnected drive in file explorer, but I could still click on it to see the files inside. Is ansible unable to find the share folder path because the drive is disconnected? How do I use Ansible to connect to the drive successfully so that it can search for files inside the share folder?
The task was able to produce the correct output after I input become, become_method, and become_user in win_find task:
- name: Search for files in Data folder
win_find:
paths: \\10.14.2.130\shared\folder\Data\
register: file1
become: yes
become_method: runas
become_user: SYSTEM