Something like the following would do it, with your current data structure.

{% for k, v in customers|dictsort if v.status == 'active' %}{{ k }}{% if
not loop.last %},{% endif %}{% endfor %}

If you rewrote your data structure to look like:

customers:
    - name: abc:
      id: 1
      status: active

Then it could be:

{{ customers|selectattr('status', 'match',
'active')|map(attribute='name')|join(',') }}

On Thu, Apr 6, 2017 at 3:10 AM, The Gripmaster <
[email protected]> wrote:

> I have a dictionary like this
>
> customers:
>   abc:
>     id: 1
>     status: active
>   def:
>     id: 2
>     status: inactive
>   ghi:
>     id: 3
>     status: active
>   jkl:
>     id: 4
>     status: active
>
>
> What's the best way to construct a string like below of the active
> customers only?
>
> abc,ghi,jkl
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/ansible-project/a12df541-e10f-4aad-a486-18a277c1f358%40googlegroups.
> com
> <https://groups.google.com/d/msgid/ansible-project/a12df541-e10f-4aad-a486-18a277c1f358%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAD8N0v_pHHLiao4Z8QvW%2BXPwcQddwk%3Di6h9NzuWoq4V599uGRg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to