I think this is because 'update' is a reserved word:

https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#creating-valid-variable-names

I'm seeing the same behavior with 'pop' for instance (though not with
many others).

Dick

On Thu, 18 Jul 2019 at 15:32, Dick Visser <[email protected]> wrote:
>
> Hi
>
> I'm seeing some weird behaviour trying to use selectattr() on a list
> of dicts, when the attribute name I am using is the literal string
> 'update'.
> Anything else works fine.
>
> Example playbook:
>
>
> ---
>
> - name: Test playbook
>   hosts: localhost
>   connection: local
>
>   vars:
>     repos:
>       - src: git+ssh://[email protected]/repo1
>         version: v1.0.1
>
>       - src: git+ssh://[email protected]/repo2
>         version: v1.1.2
>
>       - src: git+ssh://[email protected]/repo3
>         version: v1.9.2
>
>       - src: git+ssh://[email protected]/repo4
>         version: v5.7
>         update: something
>
>       - src: git+ssh://[email protected]/repo5
>         version: v1.4
>         update2: something
>
>
>   tasks:
>     - set_fact:
>         myrepos1: "{{ repos | selectattr('update2', 'defined') | list }}"
>         myrepos2: "{{ repos | selectattr('update', 'defined') | list }}"
>
>     - debug: var=myrepos1
>     - debug: var=myrepos2
>
>
> The output of the debug tasks is:
>
> TASK [debug] 
> ******************************************************************************************************************************
> ok: [localhost] => {
>     "myrepos1": [
>         {
>             "src": "git+ssh://[email protected]/repo5",
>             "update2": "something",
>             "version": "v1.4"
>         }
>     ]
> }
>
> TASK [debug] 
> ******************************************************************************************************************************
> ok: [localhost] => {
>     "myrepos2": [
>         {
>             "src": "git+ssh://[email protected]/repo1",
>             "version": "v1.0.1"
>         },
>         {
>             "src": "git+ssh://[email protected]/repo2",
>             "version": "v1.1.2"
>         },
>         {
>             "src": "git+ssh://[email protected]/repo3",
>             "version": "v1.9.2"
>         },
>         {
>             "src": "git+ssh://[email protected]/repo4",
>             "update": "something",
>             "version": "v5.7"
>         },
>         {
>             "src": "git+ssh://[email protected]/repo5",
>             "update2": "something",
>             "version": "v1.4"
>         }
>     ]
> }
>
>
>
> Any clues as to what is going on here...?
>
>
>
> --
> Dick Visser
> Trust & Identity Service Operations Manager
> GÉANT



-- 
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

-- 
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/CAL8fbwPVi8SVOar4%2B0t4hsgCTX1yxYmSC3B_26CZOCcEmVxxrQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to