r/ansible•
clevarius

Extract users from /etc/group

I have to extract users for each group in /etc/group. It's easy to get the groups with

  - name: Gather group facts
    command: getent group "{{ item.name }}"
    loop: "{{ mhgroups }}"
    register: group

where mhgroups contains all expected groups. Missing groups can be identified afterwards with

  - assert:
      msg: "CMSG {{ ansible_nodename}}, Missing group: {{ item.item.name }}"
      that:
        - item.rc == 0
    loop: "{{ group.results }}"

But how can I extract the groups from bdadm:x:32193:bd,www,galdo?

My idea is to split(':') the string and drop the first three elements. Which is the best way to drop these three elements? With map('extract,...) I can select elements but I want to reject [1,2,3]. Other ideas are welcome :-)

Posted Sep 11, 2018, 2:53 PM UTC

15
Loading comments…