# how to determine group's id?

**URL:** <https://forum.ansible.com/t/how-to-determine-groups-id/33397>\
**Category:** Ansible Project\
**Created:** [July 14, 2020, 7:58pm UTC](https://forum.ansible.com/t/how-to-determine-groups-id/33397 "2020-07-14T19:58:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laci](https://avatars.discourse-cdn.com/v4/letter/l/c67d28/32.png) [@Laci](https://forum.ansible.com/u/Laci)\
**Post date:** [July 14, 2020, 7:58pm UTC](https://forum.ansible.com/t/how-to-determine-groups-id/33397/1 "2020-07-14T19:58:13Z")

</div>

Do you guys have a good idea what is the best way to determine a group’s id them reuse that in a variable?

For ex:

% getent group monitor  
monitor:x:990:polkitd

I need 990, then I have to add a line to /etc/fstab including 990  
Thanks!

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [July 14, 2020, 9:02pm UTC](https://forum.ansible.com/t/how-to-determine-groups-id/33397/2 "2020-07-14T21:02:56Z")

</div>

```auto
Hi,

Not tested, but should be closed to what you're looking into :

- getent:
    database: group
    key: monitor
    split: ':'

- debug:
    var: getent_group[1]

```

Regards,

JYL

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [July 14, 2020, 9:10pm UTC](https://forum.ansible.com/t/how-to-determine-groups-id/33397/3 "2020-07-14T21:10:38Z")

</div>

For example

&nbsp;&nbsp;- getent:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;database: group  
&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: getent\_group.nobody

gives

&nbsp;&nbsp;getent\_group.nobody:  
&nbsp;&nbsp;- '\*'  
&nbsp;&nbsp;- '65534'

---

<div class="post-metadata">

**Author:** ![Laci](https://avatars.discourse-cdn.com/v4/letter/l/c67d28/32.png) [@Laci](https://forum.ansible.com/u/Laci)\
**Post date:** [July 15, 2020, 1:34pm UTC](https://forum.ansible.com/t/how-to-determine-groups-id/33397/4 "2020-07-15T13:34:10Z")

</div>

Thank you guys, this fixes the first part.  
But how do I reuse the output of getent, I tried, the following but didn’t work

- getent:  
database: group

- debug:  
var: getent\_group.monitor

- name: add line to fstab  
lineinfile:  
path: /etc/fstab  
line: proc /proc proc defaults,hidepid=2,gid={{ var }} 0 0

"The task includes an option with an undefined variable. The error was: ‘var’ is undefined

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [July 15, 2020, 2:28pm UTC](https://forum.ansible.com/t/how-to-determine-groups-id/33397/5 "2020-07-15T14:28:06Z")

</div>

Use "mount". It will create the entry in fstab  
[https://docs.ansible.com/ansible/latest/modules/mount\_module.html](https://docs.ansible.com/ansible/latest/modules/mount_module.html)

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [July 15, 2020, 2:56pm UTC](https://forum.ansible.com/t/how-to-determine-groups-id/33397/6 "2020-07-15T14:56:58Z")

</div>

> - getent:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;database: group  
> &nbsp;&nbsp;- debug:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: getent\_group.monitor
> 
> &nbsp;&nbsp;- name: add line to fstab  
> &nbsp;&nbsp;&nbsp;&nbsp;lineinfile:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: /etc/fstab  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line: proc /proc proc defaults,hidepid=2,gid={{ var }}  
> 0 0

Set the variable first. "gid" is the second item in the list. For example

&nbsp;&nbsp;&nbsp;&nbsp;- getent:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;database: group  
&nbsp;&nbsp;&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_gid: "{{ getent\_group.monitor.1 }}"

See if this is what you want

&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: my\_gid

Then use this variable to mount procfs. For example

&nbsp;&nbsp;&nbsp;&nbsp;- mount:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: proc  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: /proc  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fstype: proc  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opts: "defaults,hidepid=2,gid={{ my\_gid }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dump: 0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;passno: 0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;backup: true  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: mounted

(not tested)

It's a good idea to "backup: true" /etc/fstab. Take a look at the parameter  
"state" and decide when you want to mount procfs.

Check the playbook first and see what's going to be changed

---

<div class="post-metadata">

**Author:** ![Laci](https://avatars.discourse-cdn.com/v4/letter/l/c67d28/32.png) [@Laci](https://forum.ansible.com/u/Laci)\
**Post date:** [July 15, 2020, 3:42pm UTC](https://forum.ansible.com/t/how-to-determine-groups-id/33397/7 "2020-07-15T15:42:03Z")

</div>

Thank you, this did it:

- name: set fact for group  
set\_fact:  
group\_id: “{{ getent\_group.monitor[1] }}”

- name: Add proc to fstab and mount it  
mount:  
path: /proc  
src: proc  
fstype: proc  
opts: “defaults,hidepid=2,gid={{ group\_id }}”  
dump: 0  
passno: 0  
backup: true  
state: mounted
