How to add current user to group?

500 views
Skip to first unread message

Robert Lu

unread,
Dec 9, 2015, 8:56:52 AM12/9/15
to Ansible Project
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.

Brian Coca

unread,
Jan 23, 2016, 12:02:50 AM1/23/16
to Ansible Project
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.



--
Brian Coca
Reply all
Reply to author
Forward
0 new messages