Looping With 'with_nested' - Wrong Syntax?

Hi All,

I know there’s a simple fix for this, but I’ve been running 'round the Net for hours now and I can’t crack this issue - could someone please point me in the right direction?

vars/main.yml File:

variable_one:
  - var_1_1
  - var_1_2

variable_two:
  - var_2_1
  - var_2_2

task File:

- name: Copy Template Files
    ansible.builtin.template:
      src: "my_source/mytemplate_{{item.0}}.j2"
      dest: "my_destination/{{item.0}}_{{item.1}}.txt"
      owner: me
      group: me
      mode: "0640"
    with_nested:
      - "{{variable_one}}"
      - "{{variable_two}}"

Expected Output (in no particular order):

my_destination/var_1_1_var_2_1.txt
my_destination/var_1_1_var_2_2.txt"
my_destination/var_1_2_var_2_1.txt"
my_destination/var_1_2_var_2_2.txt"

Issue:

The ‘Copy Template Files’ task is trying to find:

my_source/mytemplate_[.j2
my_source/mytemplate_v.j2
my_source/mytemplate_a.j2
my_source/mytemplate_r.j2
...

In other words, its looping over the individual characters of var_1_1 and var_1_2 instead of looping of var_1_1 and var_1_2.

So my syntax is wrong (or I’m using the wrong Ansible function).

Any ideas?

Thanks in Advance
Dulux Oz

In 2.21, the loop

- debug:
    msg: |
      src: "my_source/mytemplate_{{ item.0 }}.j2"
      dest: "my_destination/{{ item.0 }}_{{ item.1 }}.txt"
  with_nested:
    - "{{ variable_one }}"
    - "{{ variable_two }}"

Works as expected

ok: [localhost] => (item=['var_1_1', 'var_2_1']) => 
    msg: |-
        src: "my_source/mytemplate_var_1_1.j2"
        dest: "my_destination/var_1_1_var_2_1.txt"
ok: [localhost] => (item=['var_1_1', 'var_2_2']) => 
    msg: |-
        src: "my_source/mytemplate_var_1_1.j2"
        dest: "my_destination/var_1_1_var_2_2.txt"
ok: [localhost] => (item=['var_1_2', 'var_2_1']) => 
    msg: |-
        src: "my_source/mytemplate_var_1_2.j2"
        dest: "my_destination/var_1_2_var_2_1.txt"
ok: [localhost] => (item=['var_1_2', 'var_2_2']) => 
    msg: |-
        src: "my_source/mytemplate_var_1_2.j2"
        dest: "my_destination/var_1_2_var_2_2.txt"

(source)