selectattr() returns everything when attribute is 'update'?

11 views
Skip to first unread message

Dick Visser

unread,
Jul 18, 2019, 9:32:53 AM7/18/19
to ansible...@googlegroups.com
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://g...@blah.com/repo1
version: v1.0.1

- src: git+ssh://g...@blah.com/repo2
version: v1.1.2

- src: git+ssh://g...@blah.com/repo3
version: v1.9.2

- src: git+ssh://g...@blah.com/repo4
version: v5.7
update: something

- src: git+ssh://g...@blah.com/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://g...@blah.com/repo5",
"update2": "something",
"version": "v1.4"
}
]
}

TASK [debug] ******************************************************************************************************************************
ok: [localhost] => {
"myrepos2": [
{
"src": "git+ssh://g...@blah.com/repo1",
"version": "v1.0.1"
},
{
"src": "git+ssh://g...@blah.com/repo2",
"version": "v1.1.2"
},
{
"src": "git+ssh://g...@blah.com/repo3",
"version": "v1.9.2"
},
{
"src": "git+ssh://g...@blah.com/repo4",
"update": "something",
"version": "v5.7"
},
{
"src": "git+ssh://g...@blah.com/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

unread,
Jul 18, 2019, 9:46:22 AM7/18/19
to ansible...@googlegroups.com
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

Kai Stian Olstad

unread,
Jul 27, 2019, 11:19:42 AM7/27/19
to ansible...@googlegroups.com
On 18.07.2019 15:45, Dick Visser wrote:
> 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).

I would consider this a bug, since returning data when query REST API
could be anything and Ansible need to handle that.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages