Search code examples
packer

Packer Script exited with non-zero exit status : 127


I am trying to provision an AWS AMI but the packer script terminates with the following error.

Build 'amazon-ebs' errored: Script exited with non-zero exit status: 127
   ==> Some builds didn't complete successfully and had errors:
   --> amazon-ebs: Script exited with non-zero exit status: 127
   ==> Builds finished but no artifacts were created.

My template for Packer is as follows:

   { 
   "variables": {
    "aws_access_key": "{{env `MY_ACCESS_KEY`}}",
    "aws_secret_key": "{{env `MY_SECRET_KEY`}}"
   },
    "builders": [{
    "type": "amazon-ebs",
    "access_key": "{{user `aws_access_key`}}",
    "secret_key": "{{user `aws_secret_key`}}",
    "region": "us-east-1",
    "source_ami":"ami-8c1be5f6",
    "instance_type": "t2.micro",
    "ssh_username": "ec2-user",
    "ami_name": "packer-example {{timestamp}}"
    }],
    "provisioners":[
    {
      "type": "shell",
      "script": "provision.sh"
    }]}

Error log is as follows: PACKER_LOG=1 packer build template.json

2017/11/01 01:30:37 [INFO] (telemetry) ending amazon-ebs
2017/11/01 01:30:37 [INFO] (telemetry) found error: Script exited with non-zero exit status: 127
2017/11/01 01:30:37 ui error: Build 'amazon-ebs' errored: Script exited with non-zero exit status: 127
2017/11/01 01:30:37 Builds completed. Waiting on interrupt barrier...
2017/11/01 01:30:37 machine readable: error-count []string{"1"}
2017/11/01 01:30:37 ui error: 
==> Some builds didn't complete successfully and had errors:
2017/11/01 01:30:37 machine readable: amazon-ebs,error []string{"Script exited with non-zero exit status: 127"}
2017/11/01 01:30:37 ui error: --> amazon-ebs: Script exited with non-zero exit status: 127
2017/11/01 01:30:37 ui: 
==> Builds finished but no artifacts were created.
Build 'amazon-ebs' errored: Script exited with non-zero exit status: 127

provision.sh comprises of

   #!/bin/bash
   sudo yum install httpd -y
   sudo yum update -y
   sudo aws s3 cp s3://zbcxlkxcjvlxkj/index1.html /var/www/html/ --region us-east-1
   sudo service httpd start
   sudo chkconfig httpd on

Solution

  • Exit code 127 is returned by bash when a command is not found. Most likely you do not have all of the commands used in your script installed on your image prior to running it.