Packer Configuration

Guide me about this error???

i have three files in packer directory…
1)template.json
2)vars.json
3)apache.sh

Would you be able to share your template.json file, @hafizzainansari777?

------template.json------

{
  "variables": {
    "aws_access_key": "",
    "aws_secret_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": "amzn2-ami-hvm-2.0.*.1-x86_64-ebs",
          "root-device-type": "ebs"
        },
        "owners": [
          "amazon"
        ],
        "most_recent": true
      },
      "instance_type": "t2.micro",
      "ssh_username": "{{user `ssh_username`}}",
      "ami_name": "packer-example {{timestamp}}",
	  "tags":{
		"Name": "JavaHome - {{timestamp}}"
	  }
    }
  ],
  "provisioners": [
    {
      "type": "shell",
      "script": "apache.sh" 
    }
  ]
}

-----vars.json-----

{
 "access_key": "",
 "secret_key": "",
 "ssh-username": "centos"
}

------apache.sh-----

#!/bin/bash

sudo yum install httpd -y
sudo service httpd start
sudo chkconfig httpd on

sudo touch /var/www/html/index.html

sudo chmod 777 /var/www/html/index.html

echo "<h1>This app is deployed by packer <h1>" /var/www/html/index.html

It appears as though you’re experiencing two issues. One is that your cloud credentials aren’t getting read into your configuration. Do you have an active AWS account and valid AWS secret and access keys? (NOTE: Please do not post them here).

In this Packer JSON file, I saw that you specified that you wanted to use CentOS 7 and not Amazon Linux 2 , in that case, you can use this template JSON file.

{
  "variables": {
    "aws_access_key": "",
    "aws_secret_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": "CentOS 7.* x86_64",
          "root-device-type": "ebs"
        },
        "owners": ["125523088429"],
        "most_recent": true
      },
      "instance_type": "t2.micro",
      "ssh_username": "centos",
      "ami_name": "packer-example {{timestamp}}",
      "tags": {
        "Name": "JavaHome - {{timestamp}}"
      }
    }
  ],
  "provisioners": [
    {
      "type": "shell",
      "script": "apache.sh"
    }
  ]
}

After this change…
“name”: “CentOS 7.* x86_64”,

now we have new error…

Howdy, @hafizzainansari777 - that appears to be an issue with your AWS credentials. Can you ensure that you have those set properly (see: Where’s My Secret Access Key? | AWS Security Blog for more information)

Successfully create Ami
Thankx for your help :kissing_heart:

now i need to add vault binary in that packer build???

I’m glad to hear you got your AMI created, @hafizzainansari777!

When it comes to installing the Vault binary, the Linux steps in this learn guide is a great set of instructions to follow along with.

1 Like

It appears as if you’re experiencing two issues. One is that your cloud credentials aren’t getting read into your configuration. does one have a lively AWS account and valid AWS secret and access keys?