How to create function call in ansible

19 views
Skip to first unread message

Jenisha T

unread,
Jul 21, 2020, 8:19:33 AM7/21/20
to Ansible Project
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!

Gajendra Gaikwad

unread,
Jul 21, 2020, 8:47:42 AM7/21/20
to ansible...@googlegroups.com
Why you are using ls -l command and
For checking user group use below  command
# id username | grep -i groupname

Regard 
Gg

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/55b0c249-8f63-41e6-bac3-4a9c3e90abfbn%40googlegroups.com.

Stefan Hornburg (Racke)

unread,
Jul 21, 2020, 9:27:30 AM7/21/20
to ansible...@googlegroups.com
On 7/21/20 2:47 PM, Gajendra Gaikwad wrote:
> 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

>
> On Tue, 21 Jul 2020, 17:49 Jenisha T, <joy...@gmail.com <mailto:joy...@gmail.com>> wrote:
>
> 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!
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> <https://groups.google.com/d/msgid/ansible-project/55b0c249-8f63-41e6-bac3-4a9c3e90abfbn%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAG_8SgMYJFVq2cp_4kWZfC1u5z1ZQj3w-fXjO8xvD5GD%3DQG91Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAG_8SgMYJFVq2cp_4kWZfC1u5z1ZQj3w-fXjO8xvD5GD%3DQG91Q%40mail.gmail.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc
Reply all
Reply to author
Forward
0 new messages