Thoughts on role for creating multiple users

Hi,

Currently, I’m transforming my user role from creating one user to creating multiple users. In many examples I’ve seen this is done by adding with_items to every tasks related to the creation of the user (create user, add authorized key, etc). This would result in executing every tasks for every listed user before moving to the next tasks (right?) But what I want is that the whole task file is run from top to bottom, for every listed user.

I’ve tried this approach: https://gist.github.com/Appeltabak/7f20f9f6e4fed80202cc2dd5d0044b5f
Unfortunately, this gives an undefined variable error when the outer_users is used in subsequent tasks.

TL;DR How can I run a task file with with_items ?

Thanks

OK - so you define your user vars like this in vars/users.yml:

users:
   - name: User of apples
     user: apple
     uid: 500
     home: /home/apple
     shell: /bin/bash
   - name: Orange Guy
     user: orange
     uid: 501
     home: /home/orange
     shell: /bin/bash

Then a basic playbook would be: