Packer template BELOW
{
"variables": {
"aws_access_key": "{{env `PACKER_VAR_DEV_AWS_ACCESS_KEY_ID`}}",
"aws_secret_key": "{{env `PACKER_VAR_DEV_AWS_SECRET_ACCESS_KEY`}}"
},
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "us-east-1",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "Base-AMI-Ubuntu-*",
"root-device-type": "ebs"
},
"owners": [
"622297214873"
],
"most_recent": true
},
"instance_type": "t2.large",
"ssh_username": "ubuntu",
"ami_name": "redacted-{{timestamp}}",
"vpc_id": "redacted",
"associate_public_ip_address": "true",
"subnet_id": "redacted"
}],
"provisioners": [{
"type": "file",
"source": "/tmp/redacted.sh",
"destination": "/tmp/redacted.sh"
},
{
"type": "shell",
"execute_command": "echo 'packer' | sudo -E sh -c '{{ .Vars }} {{ .Path }}'",
"script": "/tmp/redacted.sh"
}]
}
redacted.sh script below
#!/bin/bash -x
ScriptPath="/tmp/"
ScriptName="runComposer.sh"
set -ex
clear
sleep 15
sudo chmod a+x $ScriptName
sleep 5
$ScriptPath/$ScriptName
result=$?
ERROR BELOW from PACKER DEBUG OUTPUT LOGGING
2020/04/01 15:51:27 packer-builder-amazon-ebs plugin: [DEBUG] starting remote command: echo 'packer' | sudo -E sh -c 'PACKER_BUILDER_TYPE='amazon-ebs' PACKER_BUILD_NAME='amazon-ebs' /tmp/script_883.sh'
==> amazon-ebs: + ScriptPath=/tmp/
==> amazon-ebs: + ScriptName=runComposer.sh
==> amazon-ebs: + set -ex
==> amazon-ebs: + clear
2020/04/01 15:51:27 packer-builder-amazon-ebs plugin: [ERROR] Remote command exited with '1': echo 'packer' | sudo -E sh -c 'PACKER_BUILDER_TYPE='amazon-ebs' PACKER_BUILD_NAME='amazon-ebs' /tmp/script_883.sh'
2020/04/01 15:51:27 packer-builder-amazon-ebs plugin: [INFO] RPC endpoint: Communicator ended with: 1
2020/04/01 15:51:27 [INFO] 0 bytes written for 'stdout'
2020/04/01 15:51:27 [INFO] 108 bytes written for 'stderr'
2020/04/01 15:51:27 [INFO] RPC client: Communicator ended with: 1
2020/04/01 15:51:27 [INFO] RPC endpoint: Communicator ended with: 1
2020/04/01 15:51:27 packer-provisioner-shell plugin: [INFO] 0 bytes written for 'stdout'
2020/04/01 15:51:27 packer-provisioner-shell plugin: [INFO] 108 bytes written for 'stderr'
2020/04/01 15:51:27 packer-provisioner-shell plugin: [INFO] RPC client: Communicator ended with: 1
==> amazon-ebs: 'unknown': I need something more specific.