[go: nahoru, domu]

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

use_linux_pathing = true still expects a Windows Path #12848

Open
ejbolt opened this issue Feb 17, 2024 · 2 comments
Open

use_linux_pathing = true still expects a Windows Path #12848

ejbolt opened this issue Feb 17, 2024 · 2 comments

Comments

@ejbolt
Copy link
ejbolt commented Feb 17, 2024

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

When filing a bug, please include the following headings if possible. Any
example text in this template can be deleted.

Overview of the Issue

I'm trying to leverage shell-local to do some preparation steps before a packer build in my builder, and I'm doing my testing from WSL. According to the example in the docs, I can run a bash script and seemingly use a Linux-style path. However, I receive the following error when I do so:

There was an error splitting your absolute path; expected to find a drive
following the format ':/' but did not: absolute path:
/home/<user>/test/scripts/test.sh

Reproduction Steps

Steps to reproduce this issue:

  1. Create a simple packer file using the null source and builder
  2. Use a small bash script that echoes a message.
  3. Run packer validate . or packer build .

Packer version

Packer v1.10.1

Simplified Packer Template

source "null" "test-shell-local" {
  ssh_host = "127.0.0.1"
  ssh_username = "<user>"
  ssh_password = "<password>"
}

build {
  sources = ["sources.null.test-shell-local"]

  provisioner "shell-local" {
    # Making WSL-friendly
    environment_vars  = ["SHELLLOCALTEST=ShellTest3"]
    execute_command   = ["bash", "-c", "{{.Vars}} {{.Script}}"]
    use_linux_pathing = true
    script            = "./scripts/test.sh"
    }

}

Operating system and Environment details

OS: Windows 11 Pro
Windows Version: 23H2
Windows Build: 22631.3155
WSL2 version: 2.0.9.0
Ubuntu version: 22.04.04

Log Fragments and crash.log files

Error: Failed preparing provisioner-block "shell-local" ""
  on test.pkr.hcl line 10:

  (source code not available)
  on test.pkr.hcl line 10:

  (source code not available)
There was an error splitting your absolute path; expected to find a drive

following the format ':/' but did not: absolute path:
/home/<user>/test/scripts/test.sh

There was an error splitting your absolute path; expected to find a drive
2024/02/17 10:11:54 [INFO] (telemetry) Finalizing.
following the format ':/' but did not: absolute path:
/home/<user>/test/scripts/test.sh
@ejbolt ejbolt added the bug label Feb 17, 2024
@nywilken
Copy link
Member

Hi @ejbolt thanks for reaching out. Looking at the provided template I see that the script path ("./scripts/test.sh") is expressed as a Linux path and not as a Windows path, which is looks to be the culprit here. This is not documented alongside the attribute use_linux_pathing but the provisioner expects the script path to be Windows path, which Packer then converts behind the scenes to a Linux path.

Have you tried using the Windows path for the script?

Looking at the example you see the use of an absolute Windows path. Looking at the SDK I see that the provisioner validates for a Windows absolute path then converts it to a Linux absolute path prior to executing.

Please try using a Windows path and let me know if it resolves your issue.

@ejbolt
Copy link
Author
ejbolt commented Mar 16, 2024

Hey @nywilken, thanks for the response.

As it turns out, I was being quite silly! When looking at the examples that mention WSL,, I thought I had to use those options when the script was inside the WSL guest. As it turns out, I can use it as I would on any Linux host:

provisioner "shell-local" {
    # Making WSL-friendly
    inline = ["git clone <anisble playbooks repo>"]
  }

I did, however, move my test script to the Windows filesystem, for sake of making sure I understand the use case:

provisioner "shell-local" {
    # Making WSL-friendly
    environment_vars  = ["SHELLLOCALTEST=ShellTest3"]
    execute_command   = ["bash", "-c", "{{.Vars}} {{.Script}}"]
    use_linux_pathing = true
    scripts            = ["C:/Users/<user>/scripts/test.sh"]
}

However, packer validate and packer build throw errors that the file does not exist, which is strange.

Is this perhaps only for WSL1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants