setting variables inside a loop

Hi,

I think I’m missing something obvious, so please point me in the right direction (ansible 2.3).

  • name: load and run services
    include_role:
    name: “resource_{{ item.resource }}”
    vars:
    resource: “{{ item }}”
    with_items:
  • “{{ services }}”

How do I set the var (‘resource’) to something dependent on my item? Whatever syntax I try I always end up with a literal and not the value. Is setting variables using loop values not supported?

kind regards
Pshem

you want:

loop_control:
   loop_var: resource

Turns out it’s actually a bug in ‘include_role’ - a bunch of tickets have been opened about this. The general issue is that various types of variables are not visible inside the ‘include_role’ scope. (see here: https://github.com/ansible/ansible/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20include_role%20vars )

For now I’ve replaced the ‘include_role’ with ‘include’ and a bunch of hacks to get the paths right.

kind regards
Pshem