On Saturday, April 7, 2018 at 8:50:44 AM UTC-4, Gabriel Forster wrote:
>
> Using the find module to find unknown files in a given directory and 
> register the results as a variable to be looped through later on. The debug 
> of the registered var shows a full on array of all kinds of attributes 
> about the files (way more than I want) - except the file name! It does show 
> the file name in the files.path, which I should be able to filter with 
> basename, but that doesn't work either. This either should be much more 
> straightforward, or my understanding of this is way off.
>
> Question: How do I store unknown file names in a dir as a list that I can 
> loop through in a subsequent task?
>
>
> My current play (I've tried a few different iterations - and the echo is 
> just an example, would like to do other things like use the script module 
> and such):
>
>  ---
>  - hosts: localhost
>    tasks:
>      - name: Check the files
>        find:
>          paths: /home/gforster/projects/scripts
>        register: files_found
>  
>      - name: echo files
>        command: "echo {{ item.path | basename }}"
>        loop: "{{ files_found.files }}"
>
>
>
>
> Expected Results:
>
> TASK [echo files] 
> *********************************************************************************************************************
> changed: [localhost] => {
>     "msg": "some_filesname"
> }
>

If you want to output a message use the debug module, not "command: echo".

    - name: echo files
      debug:
        msg: "{{ item.path | basename }}"
      loop: "{{ files_found.files }}"


TASK [echo files] 
**************************************************************
ok: [localhost] => (item=None) => {
    "msg": "vault.zip"
}

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/dced9739-702b-43ec-8082-993e55dc7fa1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to