Issue
I was writing terraform code for ec2 image builder component. And getting such errors:
CmdExecution: Stderr: which: no sw_vers in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
sudo: unknown user: mkdir
sudo: unable to initialize policy plugin
The code looks like this:
"phases":
- "name": "build"
"steps":
- "action": "ExecuteBash"
"inputs":
"commands":
- "export RUNNER_ALLOW_RUNASROOT='1'"
- "yum install -y jq"
- "export RUNNER_CFG_PAT=ghp_fsdfsdfsdfsdfsdfsdfsdfd"
- "curl -s https://raw.githubusercontent.com/actions/runner/main/scripts/create-latest-svc.sh
| bash -s -- -s githubuser/githubrepo -n githubrunner -l prod"
"name": "example"
"onFailure": "Continue"
"schemaVersion": 1
Previously I thought that it's because of root user execution so I added this line:
"export RUNNER_ALLOW_RUNASROOT='1'"
but event though that is not working Do you have some ideas how to troubleshoot that
PS. terraform code:
resource "aws_imagebuilder_component" "example" {
data = yamlencode({
phases = [{
name = "build"
steps = [{
action = "ExecuteBash"
inputs = {
commands = ["export RUNNER_ALLOW_RUNASROOT='1'", "yum install -y jq", "export RUNNER_CFG_PAT=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", "curl -s https://raw.githubusercontent.com/actions/runner/main/scripts/create-latest-svc.sh | bash -s -- -s githubuser/githubrepo -n githubrunner -l prod"]
}
name = "example"
onFailure = "Continue"
}]
}]
schemaVersion = 1.0
})
name = "example33"
platform = "Linux"
version = "1.0.0"
}
Solution
I do not have much knowlege of terraform but looking at your code, it looked like you had missed initializing svc_user
which was used by your script to do various stuff e.g create a directory where it used to fail and as the sv_user
was 'null'. It would run sudo -u ${svc_user} mkdir runner
as sudo -u mkdir runner
meaning do something as user mkdir
.
It seems like you are passing root
as svc_user
now which has resolved your issue.
Answered By - Riz Answer Checked By - Senaida (WPSolving Volunteer)