Dynamic variables when looping over a list in a role

I’ve seen a few threads about looping over a list on a role, and the currently preferred method seems to be to pass the list as a variable and do the looping in each task.

My problem is that I not only want to use each variable as is, but also construct new variables based on logic over multiple keys in the original list, and that would be used in several different tasks. I’ll show an example that hopefully makes more sense, but I seem to run in to this issue over and over again.

In my example case I want to set up multiple virtual hosts on a single server. Some are https and some are not, and I want to make one vhost on each port the default.

I currently have a role that accepts a single vhost parameter, and a playbook where I invoke it once for each virtual host (example is simplified):