How to create function call in ansible

Hi Team

I want to execute ls -l command twice.

  1. ls -l # check if user in group
  2. sudo adduser user_name new_group # If not in group add user to group
  3. ls -l # Check if user added to group

Is there a way I can write a shell module for $ ls -l once and call for step 1 and step 3 in ansible

Thankyou!

Why you are using ls -l command and
For checking user group use below command

id username | grep -i groupname

Regard
Gg

Why you are using ls -l command and
For checking user group use below command
# id username | grep -i groupname

Regard
Gg

That's pretty much off topic as this is not a group about shell scripts.

You should be able to replace ls with the find module in ansible.

You can add group to an user with the user module, for example:

- name: Ensure that ClamAV user is member of Exim group
  user:
    name: "clamav"
    groups: "Debian-exim"
    append: true

Regards
        Racke