HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

GitHub Actions Runner execute commands with sudo GitHub Actions

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
actionscommandswithgithubrunnersudoexecute

Problem

I have a GitHub action set on self hosted Ubuntu VPS on Linode.
I ran sudo ./svc.sh install and then ./svc.sh start. The runner is up and working but I have a command in my yaml file that needs to run as sudo. I have this command in sudoers file to run without sudo
%sudo ALL= NOPASSWD: /bin/systemctl restart twentydb.service
But still when I push on the server the following error occurs.
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper

name: restart the service
run: |
sudo systemctl restart twentydb


I also need to set up 2 more runners on the same server and same setup.

Solution

airtower-luna from GitHub community answered it here and it worked for me
Answer pasted below:
The command in your workflow file is not the same as the one in your sudoers file, sudo doesn’t know they are functionally equivalent. Use twentydb.service in the workflow, too.

Also, is the user your runner runs as in the sudo group? If not, that entry won’t apply to it. However, I’d suggest using a separate entry for the user rather than adding the runner to the sudo group.

Context

StackExchange DevOps Q#11961, answer score: 3

Revisions (0)

No revisions yet.