How to add current user to group?

Hi, all.

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


- 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.

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.