include_role with_sequence - why it runs all possible variants on all hosts?

Hi,

I’ve stumbled upon strange behviour, any ideas what am I doing wrong?

let’s say I have variables like this:

hosts:
hostnameA.tld:
min_id: 0
max_id: 5
hostnameB.tld:
min_id: 6
max_id: 11

and then if I use them in task (templatE) with_sequence, I get correct result

  • name: ‘xxxxx’
    template:
    src: ‘service_xx.conf.j2’
    dest: ‘{{ some_dir }}/service_{{ “%02d” | format(item | int) }}.conf’
    vars:
    service_id: ‘{{ item }}’
    with_sequence: start={{ hosts[inventory_hostname][‘min_id’] }} end={{ hosts[inventory_hostname][‘max_id’] }}

this will make files with 00-05 on hostnameA.tld and 06-11 on hostnameB.tld.

but if I use them with include_role like this:

  • name: ‘yyyyy’
    include_role:
    name: ‘some-role’
    vars:
    service_id: ‘{{ “%02d” | format(item | int) }}’
    with_sequence: start={{ hosts[inventory_hostname][‘min_id’] }} end={{ hosts[inventory_hostname][‘max_id’] }}

the role is run with parameter 00-11 for both machines. Any idea why?

Thanks in advance,
Gh.