Need help with ansible

Hi
I’m really frustrated with this annoying error.
I know this is a really simple playbook but I cannot figure out where the error is.


  • name : I’m creating some users and groups
    hosts: localhost,ansible1
    vars_files:
    • vars/users.yaml
    • vars/groups.yaml
      tasks:
    • name : create group from groups file
      group :
      name : “{{ item.groupname }}”
      loop : “{{ groups }}”
    • name : create users from users file
      user :
      name : “{{ item.username }}”
      groups: “{{ item.groups }}”
      generate_ssh_key : true
      ssh_key_file : .ssh/{{item.username}}
      loop : “{{users}}”

[ansible@ansible-ctl project1]$ cat vars/groups.yaml
groups:

  • groupname: sales
  • groupname : account
  • groupname : support
    [ansible@ansible-ctl project1]$ cat vars/users.yaml

users:

  • username : zahr1
    groups: sales
  • username : zibra
    groups : account
  • username : zara
    groups : support

Unfortunately the error is :

TASK [create group from groups file] *******************************************************************************************************
fatal: [localhost]: FAILED! => {“msg”: “Invalid data passed to ‘loop’, it requires a list, got this instead: {‘all’: [‘ansible5’, ‘teleport’, ‘ansible1’, ‘ansible4’, ‘ansible6’, ‘ansible2’, ‘ansible7’, ‘ansible3’], ‘ungrouped’: [‘ansible5’, ‘teleport’], ‘web’: [‘ansible1’, ‘ansible4’, ‘ansible6’], ‘db’: [‘ansible2’], ‘new’: [‘ansible7’], ‘file’: [‘ansible3’]}. Hint: If you passed a list/dict of just one element, try adding wantlist=True to your lookup invocation or use q/query instead of lookup.”}
fatal: [ansible1]: FAILED! => {“msg”: "Invalid data passed to ‘loop’, it requires a list, got this instead: {‘all’: [‘ansible5’, ‘teleport’, ‘ansible1’, ‘ansible4’, ‘ansible6’, ‘ansible2’, ‘ansible7’, ‘ansible3’], ‘ungrouped’: [‘ansible5’, ‘teleport’], ‘web’: [‘ansible1’, 'ansibl[

Finally I found out variable groups is an environment variables in ansible which refers to host groups.

groups

A dictionary/map with all the groups in inventory and each group has the list of hosts that belong to it