How do I loop over role definitions?

Let me describe what I mean. Let’s say I have the following variables defined somewhere:

users:

  • name: “{{ ansible_user_id }}”
    group: “{% if ansible_os_family|lower == ‘darwin’ %}staff{% else %}{{ ansible_user_id }}{% endif %}”
    shell: “{{ executables.zsh }}”
    template_home: “home/{{ ansible_user_id }}”
    home: “{% if ansible_os_family|lower == ‘darwin’ %}/Users/{{ ansible_user_id }}{% else %}/home/{{ ansible_user_id }}{% endif %}”
    github_username: dan
  • name: “jim”
    group: “{% if ansible_os_family|lower == ‘darwin’ %}staff{% else %}{{ ansible_user_id }}{% endif %}”
    shell: “{{ executables.zsh }}”
    template_home: “home/jim”
    home: “{% if ansible_os_family|lower == ‘darwin’ %}/Users/jim{% else %}/home/jim{% endif %}”
    github_username: jim

Then a separate variables file for a group called “dotfiles”:

file: group_vars/dotfiles.yml

Dan,

Have you tried to use the users variable on a task? Somethiong like

put the with_items clause at task level in the role tasks

OK, I’ve modified my role so that the tasks iterate over the items, but now I’m seeing a new issue:

I should point out that conditionals like this in a variable definition is a definite antipattern I would try to simplifiy:

home: “{% if ansible_os_family|lower == ‘darwin’ %}/Users/{{ ansible_user_id }}{% else %}/home/{{ ansible_user_id }}{% endif %}”