I want to search for available groups in the server and print the groups doesn’t exist.
- 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
---
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.