YaleUniversity / packer-plugin-goss

Goss Provisioner for Packer
MIT License
136 stars 45 forks source link

exec: "service": executable file not found in $PATH #5

Closed michaelwittig closed 6 years ago

michaelwittig commented 6 years ago

Hi,

I use the goss provisioner with the following config:

./packer.json

{
  "provisioners": [
     ...
    {
      "type": "goss",
      "tests": [
        "./build/goss.yaml"
      ]
    }
  ]
}

./build/goss.yaml

---
service:
  chronyd:
    enabled: true
    running: true
  codedeploy-agent:
    enabled: true
    running: true
  sshd:
    enabled: true
    running: true

The goss binary seems to be started with a PATH that does not contain sbin. On the target system:

$ which service
/sbin/service

packer output:

1516721919,,ui,say,==> stag-base: Running goss tests...
1516721919,,ui,message, stag-base: .F.F.F..........
1516721919,,ui,message, stag-base:
1516721919,,ui,message, stag-base: Failures/Skipped:
1516721919,,ui,message, stag-base:
1516721919,,ui,message, stag-base: chronyd: running: Error: exec: "service": executable file not found in $PATH
1516721919,,ui,message, stag-base:
1516721919,,ui,message, stag-base: codedeploy-agent: running: Error: exec: "service": executable file not found in $PATH
1516721919,,ui,message, stag-base:
1516721919,,ui,message, stag-base: sshd: running: Error: exec: "service": executable file not found in $PATH
1516721919,,ui,message, stag-base:
1516721919,,ui,message, stag-base: Total Duration: 0.061s

I could not figure out where PATH is actually used and where it comes from since this is a remote command. Any hints how to debug this issue?

vamegh commented 6 years ago

Hi @michaelwittig /sbin is a path which only gets set for the root user $PATH env, there is a new use_sudo option, this should make it work and actually some tests require escalated privileges depending on what is being tested, setting the use_sudo flag to true may be of help here.

michaelwittig commented 6 years ago

thanks @vamegh use_sudo is working

{
  "provisioners": [
     ...
    {
      "type": "goss",
      "use_sudo": true,
      "tests": [
        "./build/goss.yaml"
      ]
    }
  ]
}