On Tuesday, 31 December 2013 05:31:18 UTC+1, Kahlil Hodgson wrote:

Hi Kahlil,

In Jinja2.7 you have the following filters that can be used to traverse or 
> extract parts of lists:
>
> select
> selectattr
> reject
> rejectattr
> map
>
> so I believe that following would work
>
> {{ ansible_em1.ipv6 | selectattr('scope', 'local') | first | 
> attr('address') }}
>
> just off the top of my head and untested.
>
Your example looks logical, and looks like it should work, but I get this 
error when trying to use it:

TASK: [debug msg='{{ansible_em1.ipv6 | selectattr("scope", "local") | first 
| attr("address")}}'] *** 

fatal: [ns1.ams.authdns.ripe.net] => Traceback (most recent call last):

  File 
"/Users/anandb/git/gii-ansible/portable/lib/ansible/runner/__init__.py", 
line 394, in _executor

    exec_rc = self._executor_internal(host, new_stdin)

  File 
"/Users/anandb/git/gii-ansible/portable/lib/ansible/runner/__init__.py", 
line 485, in _executor_internal

    return self._executor_internal_inner(host, self.module_name, 
self.module_args, inject, port, complex_args=complex_args)

  File 
"/Users/anandb/git/gii-ansible/portable/lib/ansible/runner/__init__.py", 
line 679, in _executor_internal_inner

    module_args = template.template(self.basedir, module_args, inject, 
fail_on_undefined=self.error_on_undefined_vars)

  File 
"/Users/anandb/git/gii-ansible/portable/lib/ansible/utils/template.py", 
line 319, in template

    varname = template_from_string(basedir, varname, vars, 
fail_on_undefined)

  File 
"/Users/anandb/git/gii-ansible/portable/lib/ansible/utils/template.py", 
line 539, in template_from_string

    res = jinja2.utils.concat(rf)

  File "<template>", line 12, in root

  File "/Users/anandb/git/gii-ansible/portable/lib/jinja2/filters.py", line 
349, in do_first

    return next(iter(seq))

  File "/Users/anandb/git/gii-ansible/portable/lib/jinja2/filters.py", line 
931, in _select_or_reject

    if modfunc(func(transfunc(item))):

  File "/Users/anandb/git/gii-ansible/portable/lib/jinja2/filters.py", line 
925, in <lambda>

    name, item, args, kwargs)

  File "/Users/anandb/git/gii-ansible/portable/lib/jinja2/environment.py", 
line 438, in call_test

    raise TemplateRuntimeError('no test named %r' % name)
TemplateRuntimeError: no test named 'local'

I tried to use Google to look for examples on how to use selectattr, but 
found nothing useful. The Jinja2 documentation for this filter is quite 
sparse. If anyone has any more suggestions, I'd be grateful.

Anand

-- 
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].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to