# How to create function call in ansible

**URL:** <https://forum.ansible.com/t/how-to-create-function-call-in-ansible/33450>\
**Category:** Ansible Project\
**Created:** [July 21, 2020, 12:19pm UTC](https://forum.ansible.com/t/how-to-create-function-call-in-ansible/33450 "2020-07-21T12:19:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jenisha\_T](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@Jenisha\_T](https://forum.ansible.com/u/Jenisha_T)\
**Post date:** [July 21, 2020, 12:19pm UTC](https://forum.ansible.com/t/how-to-create-function-call-in-ansible/33450/1 "2020-07-21T12:19:33Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Gajendra\_Gaikwad1](https://avatars.discourse-cdn.com/v4/letter/g/9de053/32.png) [@Gajendra\_Gaikwad1](https://forum.ansible.com/u/Gajendra_Gaikwad1)\
**Post date:** [July 21, 2020, 12:47pm UTC](https://forum.ansible.com/t/how-to-create-function-call-in-ansible/33450/2 "2020-07-21T12:47:13Z")

</div>

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

# id username | grep -i groupname

Regard  
Gg

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [July 21, 2020, 1:26pm UTC](https://forum.ansible.com/t/how-to-create-function-call-in-ansible/33450/3 "2020-07-21T13:26:58Z")

</div>

> 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  
&nbsp;&nbsp;user:  
&nbsp;&nbsp;&nbsp;&nbsp;name: "clamav"  
&nbsp;&nbsp;&nbsp;&nbsp;groups: "Debian-exim"  
&nbsp;&nbsp;&nbsp;&nbsp;append: true

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
