# How to add current user to group？

**URL:** <https://forum.ansible.com/t/how-to-add-current-user-to-group/19969>\
**Category:** Ansible Project\
**Created:** [December 9, 2015, 5:37am UTC](https://forum.ansible.com/t/how-to-add-current-user-to-group/19969 "2015-12-09T05:37:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Lu](https://avatars.discourse-cdn.com/v4/letter/r/ed655f/32.png) [@Robert\_Lu](https://forum.ansible.com/u/Robert_Lu)\
**Post date:** [December 9, 2015, 5:37am UTC](https://forum.ansible.com/t/how-to-add-current-user-to-group/19969/1 "2015-12-09T05:37:46Z")

</div>

Hi, all.

I want to add current user to sudo and adm group, so I write follow task:

```yaml

- name: set current user to sudo and adm group
user: >
name={{ ansible_ssh_user }} groups=sudo,adm shell=/bin/bash
append=yes

```

It works in ansible 1.9, but in 2.0.0-0.7.rc2, I can’t get ansible\_ssh\_user, I use this command to test this:

ansible -i hosts log0 -m debug -a ‘msg={{ansible\_ssh\_user}}’

**How can I get current user in task?**

PS: ansible\_ssh\_user and ansible\_user cannot work.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 23, 2016, 5:02am UTC](https://forum.ansible.com/t/how-to-add-current-user-to-group/19969/2 "2016-01-23T05:02:41Z")

</div>

if you want to add the user that runs the playbook, irrespective of  
the user used to login, try:

name={{ lookup('env', 'USER") }}

ansible\_ssh\_user reflects the LOGIN user set for the remote machine,  
in 1.9 it always set it, which caused issues with .ssh/config, in 2.0  
if not set it will be None, in which case ssh uses the 'current user'  
but it ends up not being specified in Ansible.
