FWIW, not all lookup plugins are necessarily the best fit for use with `loop`. Lookups took on a set of use cases over the years, that didn't really make them the best implementation for looping. lookup or query should help identify that their goal isn't really about data manipulation, but about looking up or querying data.
Often times you may find that there are better alternatives utilizing filters, and maybe some restructuring of your task slightly. In your `with_nested` example, this would likely be better written with loop like the following: loop: "{{ users|product(databases)|list }}" vars: users: [ 'alice', 'bob' ] databases: [ 'clientdb', 'employeedb', 'providerdb' ] In an example of `with_dict` you have a few options: - debug: msg: "key: {{ item.0 }}, value: {{ item.1 }}" loop: "{{ some_dict|dictsort|list }}" or - debug: msg: "key: {{ item.key }}, value: {{ item.value }}" loop: "{{ some_dict|dict2items }}" `with_flatten` or some cases of `with_items`, could be best represented using the `|flatten` filter. In many cases, using filters, to manipulate your data, instead of using lookups is the better path than purely switching from `with_FOO` to `loop: "{{ query('FOO', ...) }}"` On Wed, May 2, 2018 at 2:02 PM, Eric Lavarde <elava...@redhat.com> wrote: > Hi Brian, > > On 2018-05-02 16:55, Brian Coca wrote:> I'm unsure what the problem you > state with strings is, `loop` also > > accepts a list directly: > > > > debug: > > msg: one line of {{ item }} > > loop: > > - item1 > > - item2 > > Yeah, my fault, I took the very simple example where the new construct > isn't really different from the old one. > > If I take the more complex example from the documentation: > > - name: give users access to multiple databases > mysql_user: > name: "{{ item[0] }}" > priv: "{{ item[1] }}.*:ALL" > append_privs: yes > password: "foo" > loop: "{{ query('nested', [ 'alice', 'bob' ], [ 'clientdb', > 'employeedb', 'providerdb' ]) }}" > > It used to be: > > - name: give users access to multiple databases > mysql_user: > name: "{{ item[0] }}" > priv: "{{ item[1] }}.*:ALL" > append_privs: yes > password: "foo" > with_nested: > - [ 'alice', 'bob' ] > - [ 'clientdb', 'employeedb', 'providerdb' ] > > What I mean is that the loop's string with the query/lookup is now a > string containing lists of strings, with no syntax highlighting and a > worse readability (and some strange behaviours if you don't get the > quoting right). > > As for the actual implementation, yours is as good as mine, important to > my eyes is that it remains a YAML structure and no string. > > KR, Eric > > PS: sorry for the first private answer, hit the wrong button... > > -- > 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/ce27ffe5-5ba2-7713-87da-7c4033089855%40redhat.com. > For more options, visit https://groups.google.com/d/optout. > -- Matt Martz @sivel sivel.net -- 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/CAD8N0v-bYArsr7Jr7XnGEZJgx0YJRNTa%3DS7QK6XK_XNiAtqYmg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.