win_shell command execution

Hi all,
I’m trying to list the files with the name of “PackageDeploy” using as below but getting all other files also in the directory.

  • win_shell: ‘dir PackageDeploy*.* /b {{directory}}\configurations\jmxterm > {{directory}}\configurations\temp’
    args:
    executable: cmd
    register: list_out

Could you please suggest the right method for list the file with name ?

You would probably need to write like this:

  • win_shell: ‘dir PackageDeploy*.* /b > {{directory}}\configurations\temp’

args:
executable: cmd
chdir: ‘{{directory}}\configurations\jmxterm’

register: list_out

But its probably much better to use win_find module https://docs.ansible.com/ansible/latest/modules/win_find_module.htmld as the results will be easier to make use of than the contents of your list_out registered variable.

  • name: find PackageDeploy files
    win_find:
    paths: ‘{{directory}}\configurations\jmxterm’
    patterns: ‘PackageDeploy*.*’
    register: package_deploy_info

Hope this helps,

Jon

Thanks Jon, it’s working now