Getting root privileges in ansible
The problem was that i had no permission to run /bin/sh. I needed to set the executable to /bin/bash - this can be done in ansible's config file. So in the current directory i created the ansible.cfg file with the following contents:
executable = /bin/bash
and that was it!
Ansible non-root sudo user and become privilege escalation
Why am I getting permission denied?
Because APT requires root permissions (see the error: are you root?
) and you are running the tasks as david
.
Per these settings:
become: true
become_user: david
become_method: sudo
Ansible becomes david
using sudo
method. It basically runs its Python script with sudo david
in front.
the user 'david' on the remote box has sudo privileges.
It means david
can execute commands (some or all) using sudo
-executable to change the effective user for the child process (the command). If no username is given, this process runs as the root
account.
Compare the results of these two commands:
$ sudo whoami
root
$ sudo david whoami
david
Back to the APT problem, you (from CLI) as well as Ansible (connecting with SSH using your account) need to run:
sudo apt-get install sqlite3
not:
sudo david apt-get install sqlite3
which will fail with the very exact message Ansible displayed.
The following playbook will escalate by default to the root user:
---
- name: Testing...
hosts: all
become: true
tasks:
- name: Just want to install sqlite3 for example...
apt: name=sqlite3 state=present
Related Topics
Npm Install -G Grunt-Cli Failed in Linux
Run Linux Command in Background and Keep Runing After Closing Ssh
Add a Directory When Creating Tar Archive
Lapack/Blas/Openblas Proper Installation from Source - Replace System Libraries with New Ones
Replace Key:Value from One File in Another File in Shellscript
Can a Gnome Application Be Automated? How
Assign Output of a Shell Command to a Variable
Run a .Net Mvc5 Application on Mono
Changing /Proc/Sys/Kernel/Core_Pattern File Inside Docker Container
How to Determine The Date-And-Time That a Linux Process Was Started
Ssh Agent Forwarding Inside Cron Jobs
Deleting All Files Except Ones Mentioned in Config File
Init Script '/Dev/Tty: No Such Device or Address' Error on Redirect
How to Run My Own Script at Every Bootup
"Segmentation Fault (Core Dumped)" Error in Fortran Gfortran Linux
How to Open The Default Text Editor in Linux
Shared Library Mysteriously Doesn't Get Linked to Application