influxdata / terraform-aws-influx

Reusable infrastructure modules for running TICK stack on AWS
https://gruntwork.io/
Apache License 2.0
51 stars 43 forks source link

install-telegraf Permission Denied #46

Open maxschommer opened 3 years ago

maxschommer commented 3 years ago

When following the examples/tick-ami example, the build finishes with:

==> tick-ami-ubuntu: Uploading C:\Users\maxschommer\Documents\Github\terraform-aws-influx\examples\tick-ami/../../modules/ => /tmp/terraform-aws-influx/modules
==> tick-ami-ubuntu: Provisioning with shell script: C:\Users\MAXSCH~1\AppData\Local\Temp\packer-shell705441023
==> tick-ami-ubuntu: /tmp/script_9674.sh: 2: /tmp/script_9674.sh: /tmp/terraform-aws-influx/modules/install-telegraf/install-telegraf: Permission denied
==> tick-ami-ubuntu: Provisioning step had errors: Running the cleanup provisioner, if present...
==> tick-ami-ubuntu: Terminating the source AWS instance...
==> tick-ami-ubuntu: Cleaning up any extra volumes...
==> tick-ami-ubuntu: No volumes to clean up, skipping
==> tick-ami-ubuntu: Deleting temporary security group...
==> tick-ami-ubuntu: Deleting temporary keypair...
Build 'tick-ami-ubuntu' errored after 3 minutes 19 seconds: Script exited with non-zero exit status: 126.Allowed exit codes are: [0]       

==> Wait completed after 3 minutes 19 seconds

==> Some builds didn't complete successfully and had errors:
--> tick-ami-ubuntu: Script exited with non-zero exit status: 126.Allowed exit codes are: [0]

==> Builds finished but no artifacts were created.

Running from Windows 10. I tried changing the inline shell scripts from "/tmp/terraform-aws-influx/modules/install-telegraf/install-telegraf --version {{user `telegraf_version`}}" to "sudo /tmp/terraform-aws-influx/modules/install-telegraf/install-telegraf --version {{user `telegraf_version`}}" and received a command not found error:

==> tick-ami-ubuntu: Uploading C:\Users\maxschommer\Documents\Github\terraform-aws-influx\examples\tick-ami/../../modules/ => /tmp/terraform-aws-influx/modules
==> tick-ami-ubuntu: Provisioning with shell script: C:\Users\MAXSCH~1\AppData\Local\Temp\packer-shell056613131
==> tick-ami-ubuntu: sudo: /tmp/terraform-aws-influx/modules/install-telegraf/install-telegraf: command not found
==> tick-ami-ubuntu: Provisioning step had errors: Running the cleanup provisioner, if present...
==> tick-ami-ubuntu: Terminating the source AWS instance...
==> tick-ami-ubuntu: Cleaning up any extra volumes...
==> tick-ami-ubuntu: No volumes to clean up, skipping
==> tick-ami-ubuntu: Deleting temporary security group...
==> tick-ami-ubuntu: Deleting temporary keypair...
Build 'tick-ami-ubuntu' errored after 2 minutes 58 seconds: Script exited with non-zero exit status: 1.Allowed exit codes are: [0]

==> Wait completed after 2 minutes 58 seconds

==> Some builds didn't complete successfully and had errors:
--> tick-ami-ubuntu: Script exited with non-zero exit status: 1.Allowed exit codes are: [0]

==> Builds finished but no artifacts were created.
brikis98 commented 3 years ago

Did you change any of the permissions on the files? Permission denied sounds like we don't have execute permissions on the script, but I see:

-rwxr-xr-x   1 3523 Oct 15 15:32 install-telegraf

So it looks like the execute permissions are there. And from there, the code is copied to the EC2 instance:

  {
    "type": "file",
    "source": "{{template_dir}}/../../modules/",
    "destination": "/tmp/terraform-aws-influx/modules"
  }

And then executed:

  {
    "type": "shell",
    "inline": [
      "/tmp/terraform-aws-influx/modules/install-telegraf/install-telegraf --version {{user `telegraf_version`}}",
    ]
  }

So my best guess is the execute permissions got lost on your local checkout?

maxschommer commented 3 years ago

I didn't change any of the file permissions, just checked it out and ran the tutorial. Hmm, I wonder if it's a Windows issue, I'll try from linux and see if the problem persists. Windows doesn't have a notion of permissions, so it might be that "executable" got lost in translation, and might need to be reapplied if coming from Windows.

https://stackoverflow.com/questions/21319716/preserving-permissions-while-copying-from-windows-to-linux

maxschommer commented 3 years ago

Ok, after running directly from linux, there were no issues following the same procedure. So I suspect permissions are getting erased in the Windows clone.

maxschommer commented 3 years ago

I just submitted a PR with a fix, it first converts all of the line endings to from DOS to unix, and then makes the files executable before running them.

brikis98 commented 3 years ago

Thanks for looking int othis!