How to switch the local connection user from root to another user

Here is my playbook

test.yml

  • name: localhost_test
    hosts: localhost
    gather_facts: false

tasks:

  • name: Run ls
    shell: ls
    register: ls_result

I am using a local ansible.cfg with this setting

remote_user = tchia

when I run this on the command line, I can see it’s using my user name
ansible-playbook -vvvv -i ./inventory test.yml

Using module file /usr/lib/python2.7/site-packages/ansible/modules/commands/command.py
ESTABLISH LOCAL CONNECTION FOR USER: tchia
EXEC /bin/sh -c ‘echo ~ && sleep 0’

However when run the same playbook through AWX, it’s not picking my my remote_user setting even though the awx log file show it’s using my ansible.cfg

ansible-playbook 2.4.1.0

2
config file = /var/lib/awx/projects/perforce_test/ansible.cfg

3
configured module search path = [u’/var/lib/awx/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]

…4

Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/pycompat24.py

28
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/six/init.py

29
Using module file /usr/lib/python2.7/site-packages/ansible/modules/commands/command.py

30
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root

31
<127.0.0.1> EXEC /bin/sh -c ‘echo ~ && sleep 0’

32

Did you try “ansible_user” ?

using “become” is another option which is probably more in line with what you want.