# Verify groups in linux server and display the groups doesn't exist using lineinfile module

**URL:** <https://forum.ansible.com/t/verify-groups-in-linux-server-and-display-the-groups-doesnt-exist-using-lineinfile-module/31820>\
**Category:** Ansible Developer\
**Created:** [December 13, 2019, 9:59pm UTC](https://forum.ansible.com/t/verify-groups-in-linux-server-and-display-the-groups-doesnt-exist-using-lineinfile-module/31820 "2019-12-13T21:59:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prudhvi1](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@Prudhvi1](https://forum.ansible.com/u/Prudhvi1)\
**Post date:** [December 13, 2019, 9:59pm UTC](https://forum.ansible.com/t/verify-groups-in-linux-server-and-display-the-groups-doesnt-exist-using-lineinfile-module/31820/1 "2019-12-13T21:59:04Z")

</div>

I want to search for available groups in the server and print the groups doesn’t exist.

```auto
- name: Checking if group exist
  lineinfile:
    dest: /etc/group
    line: "{{ item.group }}"
  check_mode: yes
  register: verify_group
  loop: "{{ UserAddList.add_users }}"
  failed_when: verify_group is not changed
  no_log: true

```

This is the input file I’m using

```auto
---
add_users:
- name: test1_123
  group: test2_123456
  additional_groups:
  - test2
  password: test1_newcdsaf
  sudo_entry: 'ALL=(ALL) NOPASSWD: ALL'
- name: test1_1234
  group: test2
  additional_groups:
  - group1
  password: test1_newcdsaf
  sudo_entry: 'ALL=(ALL) NOPASSWD: ALL'

```

I want to display message to user the groups that are not present and fail the job. Please suggest

Thanks in advance.
