Hi Kai,

Thanks for your reaction.

I think item.path won't work because of the structure of result.files. 
result.files contains a list  [..path..], [.path..]  ,So in the debug var i 
should reference item[0].path , item[1].path

I worked my way around creating a list

# create a list of policies to be defined
- name: create list of files
  debug:
    msg: "{{ result.files | map(attribute='path') | list }}"
  register: fileList


Op donderdag 1 december 2016 20:02:44 UTC+1 schreef Kai Stian Olstad:
>
> On 30. nov. 2016 09:52, fr...@tom.nl <javascript:> wrote: 
> > I am trying to process the result from the find module. The result 
> contains 
> > 3 file paths which i would  like to process in a loop. 
> > The number of files depends on the number of files found in the 
> directories 
> > and is set by result.matched 
> > 
> > Using the with_sequence loop should do the trick, i think. But i ran 
> into a 
> > problem. 
> > 
> > with_sequence: start=0 end={{ variable }}, expects {{ variable }} to be 
> an 
> > integer. Casting {{ variable | int}} results in a zero value, which 
> should 
> > be 3. 
> > 
> > Any suggestions how to solve or work around my issue? 
>
> Why not use with_items? 
>
>
> > After casting the variable correctly to an integer, off course i still 
> have 
> > to subtract 1 to set the correct index value for the results array. 
> > 
> > *Variables*: 
> > 
> > file_path: "roles/ansible-role-iamGroups/files" 
> > template_path: "roles/ansible-role-iamGroups/templates" 
> > 
> > declared_int: 3 
> > 
> > *Tasks*: 
> > 
> > - name: find files 
> >   find: 
> >     recurse: yes 
> >     patterns: "*.json" 
> >     paths: 
> > 
> "/home/user/PycharmProjects/playbook-aws-billing/roles/ansible-role-iamGroups/templates/"
>  
>
> >   register: result 
> > 
> > - name: register numbers variable 
> >   shell: "echo {{result.matched}}" 
> >   register: number 
> > 
> > - name: list number variable (==> string value 3) 
> >   debug: var=number 
> > 
> > - name: list result hard coded (works) 
> >   debug: "var=result.files[{{item}}].path" 
> >   with_sequence: "start=0 end=2 stride=1" 
>
> - name: list result 
>    debug: var=item.path 
>    with_items: result.files 
>
>
> -- 
> Kai Stian Olstad 
>

-- 
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/fcbb0993-9581-47e3-871a-00f310177261%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to