list the all the file in directory and redirect the only file name to property file

22 views
Skip to first unread message

Uppara venkat

unread,
Sep 17, 2019, 9:12:36 AM9/17/19
to ansible...@googlegroups.com
Hi,

wanted to list the files in a directory and copy the only file name into property file,
 using by win_shell: 

  - name:list the files
      win_shell: 'ls {{directory}} > {{directory}}/manifest.prob'
      register: dir_out

    - debug: var={{item}}
      with_items: dir_out.stdout_lines



out put as 


Mode                LastWriteTime         Length Name                                                                  
----                -------------         ------ ----                                                                  
-a----         9/9/2019   9:05 AM           7289 Database_0.0.100.zip                                                  
-a----         9/9/2019   9:03 AM          18447 EMC_ECS-package_0.0.100.zip                                          
-a----        9/17/2019   1:02 PM              0 file.txt                                                              
-a----         9/9/2019   9:05 AM           7434 hotfix-DDMInfra.zip                                                  
-a----         9/9/2019   9:03 AM          15631 hotfix-IIS.zip                                                        
-a----         9/9/2019   9:05 AM          16808 hotfix-QCIM1H126382-v3.zip                                        
   I don't want other information, How list only file names?                         



Walber Santos

unread,
Sep 17, 2019, 11:13:38 AM9/17/19
to ansible...@googlegroups.com
Hi uppara 

On Linux system we have a parameter -1 to list only names of files.

Walber

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAFMhZ_L7_yD7193kScoaJzDGJh6v0rxGOcg8-aO_FsZFOgN8Vw%40mail.gmail.com.
--

Walber Santos da Silva
Cel 19 98822-3269
ID 130-123-839


Uppara venkat

unread,
Sep 17, 2019, 11:36:26 AM9/17/19
to ansible...@googlegroups.com
but I'm working in Windows;
I used Command module as

  - name: list the files 
      win_command: dir /b /a-d 


fatal: [172.31.17.108]: FAILED! => {
    "changed": false,
    "cmd": "dir /b /a-d",
    "msg": "Exception calling \"SearchPath\" with \"1\" argument(s): \"Could not find file 'dir.exe'.\"",
    "rc": 2
}

got above error



--






Thanks& Regards,
venkatesulu.U
8147041026

Kai Stian Olstad

unread,
Sep 17, 2019, 1:04:53 PM9/17/19
to ansible...@googlegroups.com
On 17.09.2019 17:35, Uppara venkat wrote:
> but I'm working in Windows;
> I used Command module as
>
> - name: list the files
> win_command: dir /b /a-d
>
Use the win_find module


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages