with_nested for across multiple modules

I’m doing something like this

tasks:

  • lineinfile: dest={{ item[0] }}/.gitignore create=yes regexp=‘{{ item[1] }}’ line=‘*.{{ item[1] }}’

with_nested:

  • [ ‘/tmp/foo’, ‘/tmp/bar’ ]

  • [ ‘lck’, ‘log’, ‘Log’ ]

but then I want to do other operations on the same list of directories (item[0]).

the vars section will only take key/value pairs, not arrays.

Can I group with_nested so it’s specified once but apply to multiple modules?

Or pre build an array that will work with_items or with_nested?

I'm confused about where the problem is. Your syntax is fine and the example works, but what prevents you from using the same with_nested loop on other tasks?

Are you looking for a quicker way to reference those items than having to type out the lists over and over again?

The regex items seems like a finite list, which could become a global var. The filenames seem more dynamic so I would probably not permanently store them if they are registered results of other tasks.

Maybe we could offer more help if we understood the real use case here and what you don't* like about the example syntax given.

Are you looking for a quicker way to reference those items than having
to type out the lists over and over again?

yes, I want to specify the array of directories 1 time in 1 place, and not repeat and maintain multiple identical arrays.
after the infile module for example, I want to use the shell module to run a git command in each directory