Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Shell provisioner to redirect its output into a logfile #11907

Open
mtausig opened this issue Jul 28, 2022 · 2 comments
Open

Allow Shell provisioner to redirect its output into a logfile #11907

mtausig opened this issue Jul 28, 2022 · 2 comments
Labels
enhancement question stage/thinking Flagged for internal discussions about possible enhancements

Comments

@mtausig
Copy link

mtausig commented Jul 28, 2022

I am using a shell provisioner which writes a lot of output to stdout.
Most of the times, this output just spams my build log and I do not need, but occasionally I want to have a look at it for debugging purposes.

What I would like, is to have an extra option for the shell-provisioner to specify a local file (on the build host) where all output from my script gets redirected to.

@nywilken nywilken added enhancement question stage/thinking Flagged for internal discussions about possible enhancements labels Aug 10, 2022
@nywilken
Copy link
Contributor

Hi @mtausig thanks for reaching out. I totally understand where you are coming from. The option you are looking for here is not something that we will build into the provisioner but I could see the option of allowing Packer to write its output to some file without having to manually redirect the output. At this time this can only be done when running in debug log mode.

Packer has support for redirecting a full debug log to some file on the build host by setting the PACKER_LOG=1 and PACKER_LOG_PATH environment variables. For example PACKER_LOG=1 PACKER_LOG_PATH=build.log packer build .

By setting PACKER_LOG=1 it will enable debug log mode, which can then be written to the file defined in the PACKER_LOG_PATH environment variable. Since this is debug logging there will be more noise but you can filter down to each of the provisioners as they are named within the log.

If you have multiple shell provisioners that you need to distigush in the logs without looking at the scripts or inline commands they are running you can give each provisioner a unique name which you can then use to jump to a specific provisioner in the log.

  provisioner "shell-local" {
    name = "set-sentive-values"
    inline = ["echo ${source.name} and ${source.type}, the sensitive var: ${var.sensitive}, ${local.bip}, ${var.number}"]
  }

@sgleske-ias
Copy link

Here's an example that would make this useful: You can execute goss infrastructure tests remotely and capture JUnit formatted results for report collection in Jenkins.

ssh -nl someuser somehost sudo goss --format junit -f /tmp/goss.yaml validate > local-results.xml

And later collect local-results.xml after the packer baking completes. In the above case, stdout is a particular format (XML) and so simply outputting it to a mixed debug log is no good because it would be invalid output for the desired result.

The above command is trivial using just SSH but ideally it would be nice to have the provisioner behave like

{
    "type": "shell",
    "inline": [
        "sudo goss --format junit -f /tmp/goss.yaml validate"
    ],
    "local_output": "local-results.xml"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement question stage/thinking Flagged for internal discussions about possible enhancements
Projects
None yet
Development

No branches or pull requests

3 participants