- name: Install packages
  when: 'os_flavor == "freebsd"'
  package:
    name:
      - zsh
      - py39-jmespath # Needed on machine running ansible for json_query
    state: present

- name: Install packages
  when: 'os_flavor == "linux"'
  package:
    name:
      - zsh
      - python-jmespath # Needed on machine running ansible for json_query
    state: present

- name: Create group
  group:
    name: "{{ item.value.group | default(item.key) }}"
    gid: "{{ item.value.gid | default(omit) }}"
  loop: "{{ users | dict2items | community.general.json_query('[?value.initialize==`true`]') }}"

- name: Create group
  group:
    name: "{{ item.name }}"
    gid: "{{ item.gid | default(omit) }}"
  loop: "{{ users | dict2items | community.general.json_query('[?value.initialize==`true`].value.groups') | flatten }}"

- import_tasks: tasks/freebsd.yaml
  when: 'os_flavor == "freebsd"'

- import_tasks: tasks/linux.yaml
  when: 'os_flavor == "linux"'
