Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

win_find module failing to find files when it cannot access a single file in a Dicrectory #31898

Closed
vamshideveloper opened this issue Oct 18, 2017 · 12 comments · Fixed by #32105
Assignees
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. windows Windows community

Comments

@vamshideveloper
Copy link

vamshideveloper commented Oct 18, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

win_find

ANSIBLE VERSION
ansible 2.3.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.5 (default, Aug  2 2016, 04:20:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]

CONFIGURATION
OS / ENVIRONMENT

Running ansible from: Linux VM-TOWERFF1.iam.sungard.prod 3.10.0-514.6.1.el7.x86_64 #1 SMP Sat Dec 10 11:15:38 EST 2016 x86_64 x86_64 x86_64 GNU/Linux
managing: windows server 2008 R2 Enterprise

SUMMARY

I was trying to find all files from c:\windows\Temp with win_find module and trying to delete them with win_file module but win_find module failing with the following error
But win_find module is working fine with all dir so what i found was, in Temp dir there are some files which ansible user cannot access (delete/move/copy etc) so i think this problem is because of these files but i dont want to touch those files as i want to run win_find on 250 servers. So i just want win_find module to skip the files which it cannot access and find remaining instead of failing whole playbook

STEPS TO REPRODUCE
- name: finding files  (C:\Windows\Temp)
    win_find:
      paths: C:\\Windows\\Temp    
    register: regi_windir 
    tags: coex_windir    
    
  - name: Cleaning files older than 1 days (C:\Windows\Temp)
    win_file:
      path: "{{ item.path }}"
      state: absent                
    with_items: 
      - "{{ regi_windir.files }}"
    tags: coex_windir 
EXPECTED RESULTS

Finding all files under Temp dir and registering in regi_windir and deleting the files which were registered

ACTUAL RESULTS
ERROR:{
    "_ansible_parsed": false,
    "_ansible_no_log": false,
    "module_stderr": "Exception calling \"Open\" with \"4\" argument(s): \"The process cannot access the \r\nfile 'C:\\Windows\\Temp\\hsperfdata_VM-ASPCOEXTSM04$\\2016' because it is being \r\nused by another process.\"\r\nAt line:295 char:13\r\n+             $fp = [System.IO.File]::Open($path, [System.IO.Filemode]::Open, \r\n[Sys ...\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n~~~\r\n    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordE \r\n   xception\r\n    + FullyQualifiedErrorId : IOException\r\n \r\n\r\n",
    "changed": false,
    "module_stdout": "",
    "failed": true,
    "rc": 1,
    "msg": "MODULE FAILURE"
}
@ansibot
Copy link
Contributor

ansibot commented Oct 18, 2017

@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 bug_report module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. windows Windows community labels Oct 18, 2017
@jborean93 jborean93 self-assigned this Oct 19, 2017
@jborean93 jborean93 removed the needs_triage Needs a first human triage before being processed. label Oct 19, 2017
@jborean93
Copy link
Contributor

This looks like it is related to #26885, are you able to run the module with get_checksum: no as it seems like it is trying to get a checksum on an open file and then fails.

We should have a better error message but this should solve your issue for now.

@vamshideveloper
Copy link
Author

vamshideveloper commented Oct 23, 2017

So, i added (get_checksum: False) but it fails with the same error above

 - name: finding files older than 1 days (C:\Windows\Temp)
    win_find:
      paths: C:\\Windows\\Temp
      get_checksum: False        
    register: regi_windir 
    tags: coex_windir    
     
- name: Cleaning files older than 1 days (C:\Windows\Temp)
   win_file:
     path: "{{ item.path }}"
     state: absent                
   with_items: 
     - "{{ regi_windir.files }}"
   tags: coex_windir

@jborean93
Copy link
Contributor

That's weird $fp = [System.IO.File]::Open() should never be called if get_checksum: False and I've tested it locally to verify that. Are you able to verify that one more time making sure the error is exactly the same.

I'm going to write a patch to the module though to skip files it fails to access as that is more in line with the find module which should help in your case.

@vamshideveloper
Copy link
Author

Tried again same error

@jborean93
Copy link
Contributor

@vamsifeb27 are you able to test out the changes I've made at #32105? It should hopefully solve your issues and make win_find just skip the files it does not have access to.

@vamshideveloper
Copy link
Author

Can you please send me the link of updated module

@vamshideveloper
Copy link
Author

I am using this module in library https://github.com/jborean93/ansible/blob/22c7e08e1f27e63a55001ba88085f74d071f012c/lib/ansible/modules/windows/win_find.ps1
but i am getting below error
{
"_ansible_parsed": false,
"_ansible_no_log": false,
"module_stderr": "Parse-Args : The term 'Parse-Args' is not recognized as the name of a cmdlet, \r\nfunction, script file, or operable program. Check the spelling of the name, or \r\nif a path was included, verify that the path is correct and try again.\r\nAt line:11 char:11\r\n+ $params = Parse-Args -arguments $args -supports_check_mode $true\r\n+ ~~~~~~~~~~\r\n + CategoryInfo : ObjectNotFound: (Parse-Args:String) [], ParentCo \r\n ntainsErrorRecordException\r\n + FullyQualifiedErrorId : CommandNotFoundException\r\n \r\n\r\n",
"changed": false,
"module_stdout": "",
"failed": true,
"rc": 1,
"msg": "MODULE FAILURE"
}

@jborean93
Copy link
Contributor

If you are on Ansible 2.3, you will need to change the line near the top of the file

#Requires -Module Ansible.ModuleUtils.Legacy

to

# WANT_JSON
# POWERSHELL_COMMON

The #Requires is the new syntax to follow and was adding in 2.4 but you can still get it working with older versions by changing it.

@jborean93
Copy link
Contributor

Changes have been merged into devel and cherry-picked to 2.4. Will be available in 2.4.2 rc1 6a73339

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@findtu
Copy link

findtu commented May 2, 2018

I encountered the same issue when I use the following scripts. My ansible version is 2.5.0, any suggestions? @jborean93 Thanks.
- name: Collect RPT logs info
win_find:
paths: "{{workspace_path}}\{{project_name}}\Results"
patterns: "*.csv"
get_checksum: False
register: rpt_logs_to_copy

- debug: var=rpt_logs_to_copy      
  
- name: move the RPT logs to working foler
  win_shell: mv "{{item.path}}" "{{ __log_folder }}"
  with_items: "{{rpt_logs_to_copy.files}}"

@findtu
Copy link

findtu commented May 2, 2018

TASK [Collect RPT logs info] ***************************************************
[WARNING]: win_find failed to check some files, these files were ignored and
will not be part of the result output

@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. windows Windows community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants