Need to drop out of superuser role

35 views
Skip to first unread message

Mark Constant

unread,
Jan 12, 2016, 11:06:05 AM1/12/16
to Ansible Project
I have a playbook where I have to run a bunch of commands as sudo. So at the beginning of the playbook I put become: yes.
The issue is there is one command running a shell script where the shell script can't be run as super user. Almost like I have to deescalate privileges.
If I just run the playbook I get the error from the .sh installer that you can't run as root.
Under the name: Install Product I have tried everything to switch users to a non root user but the playbook basically hangs. I can't tell where the issue is. Nothing happens.

I have tried
Name: Install Software
become: no

Also have tried
Name: Install Software
become: yes
become_user: rhapuser
become_method: su

But no matter what I do it just stalls at TASK: Install Software

Is there a way to basically remove root privileges for just one command or figure out why it is not running?

Brian Coca

unread,
Jan 12, 2016, 11:16:08 AM1/12/16
to Ansible Project
it should be as simple as using `become: no`

here i demonstrate with a simple test:

- hosts: nyx
become: yes
tasks:
- shell: whoami
register: me

- debug: msg="{{me.stdout}}"

- shell: whoami
become: no
register: me

- debug: msg="{{me.stdout}}"



ANSIBLE_NOCOWS=1 ansible-playbook play.yml -K
SUDO password:

PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [nyx]

TASK [command] *****************************************************************
changed: [nyx]

TASK [debug] *******************************************************************
ok: [nyx] => {
"msg": "root"
}

TASK [command] *****************************************************************
changed: [nyx]

TASK [debug] *******************************************************************
ok: [nyx] => {
"msg": "bcoca"
}

PLAY RECAP *********************************************************************
nyx : ok=5 changed=2 unreachable=0 failed=0

--
Brian Coca

Mark Constant

unread,
Jan 12, 2016, 4:07:30 PM1/12/16
to Ansible Project
I think I found the issue. The issue is that when I run the installer even though I provide an answer file like the directions say the installer still prompts when I run it locally. I thought it used the answer file to just run the installer without prompts. I guess not.
Reply all
Reply to author
Forward
0 new messages