Hello. I am trying to use Packer to create an AMI and I am having problems uploading files from my machine to the ec2 instance Packer creates. I am wondering if anyone can help me decipher the log files to try and figure out where it is going wrong. Thanks.
packer --version
1.4.1
Here is my JSON with sensitive data omitted:
{
"variables": {
"environment": "X",
"contact": "XX",
"service": "XXX"
},
"builders": [
{
"profile": "preprod",
"region": "us-west-2",
"type": "amazon-ebs",
"subnet_id": "subnet-0e8f396edb63ea1d0",
"security_group_id": "sg-0cd3123385e1bd3a2",
"source_ami": "ami-0924f2f8b49a5ea9f",
"instance_type": "t2.micro",
"communicator": "ssh",
"ssh_username": "ec2-user",
"ami_name": "{{user `service`}}-Packer-{{timestamp}}",
"tags": {
"Name": "{{user `service`}}-Packer-{{timestamp}}",
"Service": "{{user `service`}}",
"Environment": "{{user `environment`}}",
"Contact": "{{user `contact`}}",
"Packer": "true"
},
"run_tags": {
"Name": "{{user `service`}} Packer Builder",
"Service": "{{user `service`}}",
"Environment": "{{user `environment`}}",
"Contact": "{{user `contact`}}",
"Packer": "true"
}
}
],
"provisioners": [
{
"type": "file",
"source": "./files/jdk-8u211-linux-x64.tar.gz",
"destination": "/home/ec2-user"
},
{
"type": "file",
"source": "./files/MarkLogic-9.0-9.2.x86_64.rpm",
"destination": "/home/ec2-user"
},
{
"execute_command": "echo 'packer' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'",
"scripts": [
"script.sh"
],
"type": "shell",
"remote_path": "/home/ec2-user/script.sh"
}
]
}
Here is the detailed log output using PACKER_LOG=1 packer build marklogic.json
starting where it connects to SSH:
==> amazon-ebs: Waiting for instance (i-0ad2289ba639f184e) to become ready...
2019/07/16 14:50:17 packer: 2019/07/16 14:50:17 [INFO] Not using winrm communicator, skipping get password...
==> amazon-ebs: Using ssh communicator to connect: 10.44.101.132
2019/07/16 14:50:17 packer: 2019/07/16 14:50:17 [INFO] Waiting for SSH, up to timeout: 5m0s
==> amazon-ebs: Waiting for SSH to become available...
2019/07/16 14:50:23 packer: 2019/07/16 14:50:23 [DEBUG] TCP connection to SSH ip/port failed: dial tcp 10.44.101.132:22: connect: connection refused
2019/07/16 14:50:28 packer: 2019/07/16 14:50:28 [INFO] Attempting SSH connection to 10.44.101.132:22...
2019/07/16 14:50:28 packer: 2019/07/16 14:50:28 [DEBUG] Config to &ssh.Config{SSHConfig:(*ssh.ClientConfig)(0xc0000ee340), Connection:(func() (net.Conn, error))(0x1d39bb0), Pty:false, DisableAgentForwarding:false, HandshakeTimeout:0, UseSftp:false, KeepAliveInterval:5000000000, Timeout:0}...
2019/07/16 14:50:28 packer: 2019/07/16 14:50:28 [DEBUG] reconnecting to TCP connection for SSH
2019/07/16 14:50:28 packer: 2019/07/16 14:50:28 [DEBUG] handshaking with SSH
2019/07/16 14:50:29 packer: 2019/07/16 14:50:29 [DEBUG] handshake complete!
2019/07/16 14:50:29 packer: 2019/07/16 14:50:29 [DEBUG] Opening new ssh session
2019/07/16 14:50:29 packer: 2019/07/16 14:50:29 [INFO] agent forwarding enabled
==> amazon-ebs: Connected to SSH!
2019/07/16 14:50:29 packer: 2019/07/16 14:50:29 Running the provision hook
2019/07/16 14:50:29 [INFO] (telemetry) Starting provisioner file
==> amazon-ebs: Uploading ./files/jdk-8u211-linux-x64.tar.gz => /home/ec2-user
2019/07/16 14:50:29 packer: 2019/07/16 14:50:29 [DEBUG] Opening new ssh session
2019/07/16 14:50:29 packer: 2019/07/16 14:50:29 [DEBUG] Starting remote scp process: scp -vt /home
jdk-8u211-linux-x64.tar.gz 544.00 KiB / 185.96 MiB [>----------------------------------------------] 0.29% 01m11s
2019/07/16 14:50:30 packer: 2019/07/16 14:50:30 [DEBUG] Started SCP session, beginning transfers...
jdk-8u211-linux-x64.tar.gz 672.00 KiB / 185.96 MiB [>----------------------------------------------] 0.35% 01m54s
2019/07/16 14:50:30 packer: 2019/07/16 14:50:30 [DEBUG] SCP session complete, closing stdin pipe.
2019/07/16 14:50:30 packer: 2019/07/16 14:50:30 [DEBUG] Waiting for SSH session to complete.
2019/07/16 14:50:30 packer: 2019/07/16 14:50:30 [DEBUG] non-zero exit status: 1
2019/07/16 14:50:30 packer: 2019/07/16 14:50:30 [DEBUG] scp output: scp: /home/ec2-user: Is a directory
2019/07/16 14:50:30 packer: scp: protocol error: expected control record
2019/07/16 14:50:30 ui error: ==> amazon-ebs: Upload failed: Process exited with status 1
==> amazon-ebs: Upload failed: Process exited with status 1
2019/07/16 14:50:30 packer: 2019/07/16 14:50:30 closing
2019/07/16 14:50:30 closing
jdk-8u211-linux-x64.tar.gz 672.00 KiB / 185.96 MiB [>--------------------------------------------------] 0.35% 0s
2019/07/16 14:50:30 [INFO] (telemetry) ending file
==> amazon-ebs: Terminating the source AWS instance...
==> amazon-ebs: Cleaning up any extra volumes...
==> amazon-ebs: No volumes to clean up, skipping
==> amazon-ebs: Deleting temporary keypair...
2019/07/16 14:51:02 [INFO] (telemetry) ending amazon-ebs
2019/07/16 14:51:02 ui error: Build 'amazon-ebs' errored: Process exited with status 1
2019/07/16 14:51:02 machine readable: error-count []string{"1"}
Build 'amazon-ebs' errored: Process exited with status 1
2019/07/16 14:51:02 ui error:
==> Some builds didn't complete successfully and had errors:
2019/07/16 14:51:02 machine readable: amazon-ebs,error []string{"Process exited with status 1"}
2019/07/16 14:51:02 ui error: --> amazon-ebs: Process exited with status 1
==> Builds finished but no artifacts were created.
==> Some builds didn't complete successfully and had errors:
2019/07/16 14:51:02 [INFO] (telemetry) Finalizing.
--> amazon-ebs: Process exited with status 1
==> Builds finished but no artifacts were created.
2019/07/16 14:51:02 waiting for all plugin processes to complete...
2019/07/16 14:51:02 /usr/local/bin/packer: plugin process exited
2019/07/16 14:51:02 /usr/local/bin/packer: plugin process exited
2019/07/16 14:51:02 /usr/local/bin/packer: plugin process exited
2019/07/16 14:51:02 [INFO] 393216 bytes written for 'uploadData'
Hey, thanks for reaching out. See the line scp output: scp: /home/ec2-user: Is a directory
?
Try "destination": "/home/ec2-user/"
instead of "destination": "/home/ec2-user"
(add a trailing slash)
This is caused because Packer calls scp which doesn't realize you're trying to upload to a directory.
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
Hey, thanks for reaching out. See the line
scp output: scp: /home/ec2-user: Is a directory
?Try
"destination": "/home/ec2-user/"
instead of"destination": "/home/ec2-user"
(add a trailing slash)This is caused because Packer calls scp which doesn't realize you're trying to upload to a directory.