On 29.01.2019 23:44, John Harmon wrote:
Figured it out.  I just call the variable with nothing else:

    - name: "Find the user_id for {{ user }}"
      set_fact:
        uid: "{{
(userinfo.json.users|selectattr('username','match',MYVAR)|list|first).user_id
}}"

Using ignore_errors is a bad practice IMHO.

If you get no hits you "|list" will be empty and you "|first" filter will fail so you need to run it through default filter.

{{ (userinfo.json.users|selectattr('username','match',MYVAR)|list|first|default([])).user_id }}"

But this will also fail since user_id doesn't exist in a empty list do you need to run that through the default filter as well.

So this should work without ignore_errors

{{ (userinfo.json.users|selectattr('username','match',MYVAR)|list|first|default([])).user_id | default('') }}"

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

Reply via email to