Iterating with fileglob?

Is there a way to iterate the fileglob with a list?

If I have 3 groups

“group1”, “group2”, “group3”

and each group is represented as a directory on the management host

/path/to/group1

/path/to/group2

/path/to/group3

and I want to look into each of those paths for *.cfg files

/path/to/group1/1.cfg
/path/to/group2/2.cfg
/path/to/group2/2_1.cfg
/path/to/group3/3.cfg

/path/to/group3/3_1.cfg

/path/to/group3/3_2.cfg

The way I understand the with_fileglob won’t work?

Example

`

  • name: my template
    template:
    src: “{{ item }}”
    dest: “/tmp//{{ item | basename }}”
    owner: root
    group: root
    mode: “0644”
    with_fileglob:
  • “{{ what_goes_here }}/*.cfg”
    `

If the groups are dynamic and different for each host I cannot hard code the with_fileglob. I need to be able to replace the list to with_fileglob with /path/to/group1 and /path/to/group2 and /path/to/group3

The easiest is to create a variable like config_path, and set that to different value for each group.
Then you can use that variable one in the with_fileglob.