Hi Kai,

On Sun, Apr 29, 2018 at 11:48:09AM +0200, Kai Stian Olstad wrote:
> On 29.04.2018 10:32, Andy Smith wrote:
> >- Is there any way to do a regexp match? I am concerned that without
> >  anchoring the "ata-" at the start or including the digits of the
> >  "-partX" bits that these strings could one day occur elsewhere in
> >  the id and erroneously exclude devices.
> 
> For the regex you could do this
> 
> {% for dev, ids in ansible_device_links.ids.iteritems() if
> ids.0.startswith('ata-') and not ids.0 | regex_search('-part[0-9]+$') %}
> {{ ids[0] }}
> {% endfor %}

Thank you very much!

I'm new to Jinja2 and was basing what I could do with it on the
contents of http://jinja.pocoo.org/docs/2.10/templates/. This has no
matches for "regex" so I thought I couldn't do that, and I also
didn't realise that I could use a method of a string object like
"startswith".

I see now that I should have been looking in the Ansible
documentation for filters, i.e.:
http://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#regular-expression-filters

Cheers,
Andy

-- 
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/20180429103730.GO4569%40bitfolk.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to