How to use Ansible service module in playbooks with limited sudo? [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I'm writing a playbook to deploy an application. I'm SSH'ing as a regular user, not root. After my application finishes deploying I want to restart its service. Obviously, to restart a service I need some sort of sudo privileges.
In my /etc/sudoers file I have:
redadmin ALL=(root) NOPASSWD: /usr/sbin/service apache2 *
However, when I run my Ansible playbook it hangs when it gets to:
- name: Restarting apache
service: name=apache2 state=restarted
sudo: yes
How can I modify my playbook to use Ansible's service module without giving redadmin user full root privileges?

Related

Does systemctl daemon-reload need to be executed using root/sudo? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 12 months ago.
Improve this question
Does systemctl daemon-reload need to be executed using root/sudo? and does the same command apply to both Centos 7 and Ubuntu 18.04.3 LTS?
$ systemctl daemon-reload
==== AUTHENTICATING FOR org.freedesktop.systemd1.reload-daemon ====
Authentication is required to reload the systemd state.
Authenticating as: neo
Password:
Yeah, I'd say so.
Unless you are doing it in a container with root privileges, pretty sure you need to have root permissions for anything related to systemd services.

restart nginx service without sudo [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I need to restart the Nginx service without a password attempt.
I find out there is a way with sudoers. so I add blow command in sudoers but it's not working. I have ubuntu 19.4.
anonymous ALL=(ALL:ALL) NOPASSWD: /usr/sbin/systemctl restart nginx
so sudo systemctl restart nginx must work without any password attempt.
Look for sudo events in /var/log/auth.log.
Confirm that systemctl is in fact at /usr/sbin/systemctl (it may be in /bin/systemctl).
Ensure that you are running as user anonymous on this system for the above sudoers to work.

change root#<name> in Ubuntu 18.04 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
On my machine i'm getting "root#umar" that I want to change to "root#junaid". I have tried running different commands. They do change my username but above mentioned name is not changing.
See in above image. User I'm logged in as is "Junaid". But before that there is "root#umar" that I want to be changed to "root#junaid". Solutions I have tried change my current username that I'm loggedIn as.
Any solution?
"umar" is the hostname. So you should change it to get prompt like "root#junaid"
To do this on the fly you should exec next command:
sudo hostname junaid
sudo vi /etc/hostname
(to update the hostname there)
and the same in hosts file
sudo vi /etc/hosts
If you run commands as root you do not need to have sudo

centos 7 cronjobs from user root run but cronjobs from user apache dont [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
When I create a cronjob with user root it get runned al fine. But when I switch to user Apache and create a cronjob it doesnt run.
What could cause this? I was thinking about so permission issue maybe but can't figure out what.
The issue is that cron tries to switch to the user's home directory before executing anything and home directory no exists.
You must create the directory.
A better solution is execute cron with sudo:
15 1 26 * * sudo -u apache /usr/bin/php /var/www/html/nextcloud/occ files:scan --path=1645FC94-D50C-4E40-B941-38CA3B88EC0F/files/ExternalStorage

Why use the service command in linux? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
What is the difference between
service apache2 restart
and
/etc/init.d/apache2 restart
So basically why is the service command recommended compared to directly invoking the appropriate command?
The service command runs the init scripts in a predictable environment:
service runs a System V init script in as predictable environment as possible, removing most environment variables and with current working directory set to /.
from: http://linux.die.net/man/8/service

Resources