Change user as root in Ansible

We have a requirement to install Siebel application using Ansible. We are trying to install Oracle Client with Siebel user which we did successfully.

Now next step we want to run one custom shell script which we want to run it using root user.

Here we are stuck as we are not able to update the sudoers file where we can provide all (root) privilege to Siebel user.

So our requirement is to enable Siebel user with root privileges in Ansible playbook where we Passwordless configuration.

Appreciate your help !!

Thanks,
Parag

Answer

To become a user in Ansible requires being able to execute any commands as that user. This is to run various modules.

If you do not want to do this, instead you can configure one rule in sudo to only allow the one script. Then run “sudo -u root /opt/app/shellscript.sh” directly, skipping any Ansible become features. (Substitute your actual script, naturally.)

However, anyone who can write to that shell script can run things as root. This is a security problem. You can install this script with root ownership, but that too will require root access.

Attribution
Source : Link , Question Author : Parag , Answer Author : John Mahowald

Leave a Comment