Hi,
I'm trying to use csvfile lookups to populate values in the groups module,
but not having much luck. My csvfile:
# groups.csv
# name, gid [optional - leave blank], state [present|absent], system
[yes|no]
accounts,502,present,no
engineering,504,present,no
The playbook:
---
- hosts: localhost
  become: True
  become_user: root
  tasks:
  - name: get groups
    command: /usr/bin/awk -F',' '!/^#/ && !/^$/ { print $1 }' groups.csv
    register: groups_out
  - name: Process groups
    group: >
      name="{{ lookup('csvfile', 'item file=groups.csv col=0') }}"
      gid="{{ lookup('csvfile', 'item file=groups.csv col=1') }}"
      state="{{ lookup('csvfile', 'item file=groups.csv col=2') }}"
      system="{{ lookup('csvfile', 'item file=groups.csv col=3') }}"
As you mention in a later post you are missing the delimiter, TAB is the default.
And you key is literally "item" on all you lookup. To use the variable item you'll have to concatenate like this.
   lookup('csvfile', item + ' file=groups.csv delimiter=, col=n')
    # with_lines: "/usr/bin/awk -F',' '!/^#/ && !/^$/ { print $1 }'
groups.csv"
    # with_items: "{{ groups_out.stdout_lines }}"
    with_lines: "{{ groups_out.stdout_lines }}"
You can't only have a variable in with_items, it must be a command
https://docs.ansible.com/ansible/playbooks_loops.html#iterating-over-the-results-of-a-program-execution
Using with_lines and groups_out.stdout_lines gives me:
TASK [Process groups]
**********************************************************
/bin/sh: accounts: command not found
You don't have /bin/sh, that can be a problem, since default, Ansible is depending on it.