Create users and groups using with_files

Trying to create groups and then users using with files and its not working…How should the lists be represented in the groups vars file and the users vars file?

It doesnt like it just as text below…how am I supposed to list the values out? How do people normally create a few users and groups like this?

groups.yml

devops
dbadmin
business

users.yml

tom
dave
joe

Playbook
— # Users and Groups

  • hosts: localhost
    vars_files:
  • groups.yml
  • users.yml
    tasks:
  • name: Create groups
    group:
    name: “{{ item }}”
    state: present
    with_file:
  • groups.yml
  • name: Create users
    user:
    name: “{{ item }}”
    state: present
    with_file:
  • users.yml

Your files are not in YAML- Syntax. Ansible should give you an error if you start the playbook. You dont event need it at all.

Use with_lines! Like this:

tasks:

  • name: Create groups
    group:
    name: “{{ item }}”
    state: present
    with_lines: cat groups.yml

  • name: Create users
    user:
    name: “{{ item }}”
    state: present
    with_lines: cat users.yml

The 'file' lookup does not deal with YAML so with_files will just
return an entry for the content of the file, 'lines' or split() should
make it work.

Since you don't specify what "doesn't work" means ... I really cannot
even guess at what the error is, always include the error you get when
you are trying to have others help debugging.