
Winning at Ansible: How to manipulate items in a list - carlosnunez
http://blog.caranna.works/2016/02/25/winning-at-ansible-how-to-manipulate-items-in-a-list/
======
alexandrerond
I don't understand this.

If you need to iterate over the items you can just use "with_items" or
"with_subelements"
([http://docs.ansible.com/ansible/playbooks_loops.html#looping...](http://docs.ansible.com/ansible/playbooks_loops.html#looping-
over-subelements)) and the "{{ item }}_12345"

If you need a list for a template you can always loop it in the template and
access the sublements there and template them as you wish.

One of the strong points of Ansible is that it can be read very easily. The
moment you do:

"{{ important_files | map(attribute='file_name') | list |
map('regex_replace','(.*)','\\\1_{{ file_suffix }}') | list }}"

you throw it away.

~~~
carlosnunez
The problem that I found with that approach for this particular use case
(maybe using files wasn't a great example, since it has its own module and
files can be templated) is that the variable itself is a list of dicts. I
found that using with_subelements or with_items for this didn't reduce the
complexity much since I still needed to resort to Jinja gymnastics to get what
I needed and then needed to worry about taking that output and casting it to a
list anyway.

